/*
 * media.wsdl web service operations
 * implemention
 *
 */

#include "../soapH.h"
#include "../onvif.h"
#include "media_service.h"

// options class name
#define CLASS_VSOPT "VideoSource Configuration Options"
#define CLASS_VEOPT "VideoEncoder Configuration Options"
#define CLASS_ASOPT "AudioSource Configuration Options"
#define CLASS_AEOPT "AudioEncoder Configuration Options"
#define CLASS_ADECOPT "AudioDecoder Configuration Options"
#define CLASS_AOOPT "AudioOutput Configuration Options"

#define CLASS_VEINST "Video Encoder Instances"

#define BUF_LEN 512
static char buff[BUF_LEN]={0};

//get configs from onvif.config file
int init_mediaservice_configs(void)
{
	// configurations
	memset(profiles,0,sizeof(profiles));
	memset(ve_configurations,0,sizeof(ve_configurations));
	memset(vs_configurations,0,sizeof(vs_configurations));
	memset(vo_configurations,0,sizeof(vo_configurations));
	memset(as_configurations,0,sizeof(as_configurations));
	memset(ao_configurations,0,sizeof(ao_configurations));
	memset(ae_configurations,0,sizeof(ae_configurations));
	memset(adec_configurations,0,sizeof(adec_configurations));

	query_all_config_default(CLASS_PROFILE,&profiles[0][0], CONFIG_NUM,&profile_num,PF_MAX_POS);
	query_all_config_default(CLASS_VECFG,&ve_configurations[0][0],CONFIG_NUM,&ve_config_num,VE_MAX_POS);
	query_all_config_default(CLASS_VSCFG,&vs_configurations[0][0],CONFIG_NUM,&vs_config_num,VS_MAX_POS);
	query_all_config_default(CLASS_VOCFG,&vo_configurations[0][0],CONFIG_NUM,&vo_config_num,VO_MAX_POS);
	query_all_config_default(CLASS_ASCFG,&as_configurations[0][0],CONFIG_NUM,&as_config_num,AS_MAX_POS);
	query_all_config_default(CLASS_AOCFG,&ao_configurations[0][0],CONFIG_NUM,&ao_config_num,AO_MAX_POS);
	query_all_config_default(CLASS_AECFG,&ae_configurations[0][0],CONFIG_NUM,&ae_config_num,AE_MAX_POS);
	query_all_config_default(CLASS_ADECFG,&adec_configurations[0][0],CONFIG_NUM,&adec_config_num,ADEC_MAX_POS);

	// configuration options
	memset(vsconfig_options,0,sizeof(vsconfig_options));
	memset(asconfig_options,0,sizeof(asconfig_options));
	memset(veconfig_options,0,sizeof(veconfig_options));
	memset(aeconfig_options,0,sizeof(aeconfig_options));
	memset(adeconfig_options,0,sizeof(adeconfig_options));
	memset(aoconfig_options,0,sizeof(aoconfig_options));

	query_all_config_default(CLASS_VSOPT,&vsconfig_options[0][0],CONFIG_NUM,&vsconfig_options_num,OPT_VS_MAX_POS);
	query_all_config_default(CLASS_ASOPT,&asconfig_options[0][0],CONFIG_NUM,&asconfig_options_num,OPT_AS_MAX_POS);
	query_all_config_default(CLASS_VEOPT,&veconfig_options[0][0],CONFIG_NUM,&veconfig_options_num,OPT_VE_MAX_POS);
	query_all_config_default(CLASS_AEOPT,&aeconfig_options[0][0],CONFIG_NUM,&aeconfig_options_num,OPT_AE_MAX_POS);
	query_all_config_default(CLASS_ADECOPT,&adeconfig_options[0][0],CONFIG_NUM,&adeconfig_options_num,OPT_ADEC_MAX_POS);
	query_all_config_default(CLASS_AOOPT,&aoconfig_options[0][0],CONFIG_NUM,&aoconfig_options_num,OPT_AO_MAX_POS);
	
	// video encoder instances
	memset(ve_instances,0,sizeof(ve_instances));
	query_all_config_default(CLASS_VEINST,&ve_instances[0][0],CONFIG_NUM,&ve_instances_num,VE_INST_MAX);

#if 0
	// temp code for inserting options params to onvif.config file
	int i;
	for(i=0;i<vsconfig_options_num;i++)
		insert_config_default_byarray(CLASS_VSOPT,vsconfig_options[i][OPT_VS_VSCLIST],vsconfig_options[i],OPT_VS_MAX_POS);
	for(i=0;i<asconfig_options_num;i++)
		insert_config_default_byarray(CLASS_ASOPT,asconfig_options[i][OPT_AS_ASCLIST],asconfig_options[i],OPT_AS_MAX_POS);
	for(i=0;i<veconfig_options_num;i++)
		insert_config_default_byarray(CLASS_VEOPT,veconfig_options[i][OPT_VE_VECLIST],veconfig_options[i],OPT_VE_MAX_POS);
	for(i=0;i<aeconfig_options_num;i++)
		insert_config_default_byarray(CLASS_AEOPT,aeconfig_options[i][OPT_AE_AECLIST],aeconfig_options[i],OPT_AE_MAX_POS);
	for(i=0;i<adeconfig_options_num;i++)
		insert_config_default_byarray(CLASS_ADECOPT,adeconfig_options[i][OPT_ADEC_ADECLIST],adeconfig_options[i],OPT_ADEC_MAX_POS);
	for(i=0;i<aoconfig_options_num;i++)
		insert_config_default_byarray(CLASS_AOOPT,aoconfig_options[i][OPT_AO_AOCLIST],aoconfig_options[i],OPT_AO_MAX_POS);

	for(i=0;i<ve_instances_num;i++)
		insert_config_default_byarray(CLASS_VEINST,ve_instances[i][VE_INST_VSCFG],ve_instances[i],VE_INST_MAX);

	for(i=0;i<veconfig_options_num;i++)
	{
		char tmp[32]={0};
		snprintf(tmp,32,"options-%02d",i);
		insert_config_default_byarray(CLASS_VEOPT,tmp,veconfig_options[i],OPT_VE_MAX_POS);
	}
#endif

	return 0;
}

//free the malloced memory spaces 
int exit_mediaservice_configs(void)
{
	//configurations
	free_all_space(&profiles[0][0],CONFIG_NUM,PF_MAX_POS);
	free_all_space(&ve_configurations[0][0],CONFIG_NUM,VE_MAX_POS);
	free_all_space(&vs_configurations[0][0],CONFIG_NUM,VS_MAX_POS);
	free_all_space(&vo_configurations[0][0],CONFIG_NUM,VO_MAX_POS);
	free_all_space(&as_configurations[0][0],CONFIG_NUM,AS_MAX_POS);
	free_all_space(&ao_configurations[0][0],CONFIG_NUM,AO_MAX_POS);
	free_all_space(&ae_configurations[0][0],CONFIG_NUM,AE_MAX_POS);
	free_all_space(&adec_configurations[0][0],CONFIG_NUM,ADEC_MAX_POS);

	memset(profiles,0,sizeof(profiles));
	memset(ve_configurations,0,sizeof(ve_configurations));
	memset(vs_configurations,0,sizeof(vs_configurations));
	memset(vo_configurations,0,sizeof(vo_configurations));
	memset(as_configurations,0,sizeof(as_configurations));
	memset(ao_configurations,0,sizeof(ao_configurations));
	memset(ae_configurations,0,sizeof(ae_configurations));
	memset(adec_configurations,0,sizeof(adec_configurations));

#if 0
	//configuration options
	free_all_space(&vsconfig_options[0][0], CONFIG_NUM, OPT_VS_MAX_POS);
	free_all_space(&asconfig_options[0][0], CONFIG_NUM, OPT_AS_MAX_POS);
	free_all_space(&veconfig_options[0][0], CONFIG_NUM, OPT_VE_MAX_POS);
	free_all_space(&aeconfig_options[0][0], CONFIG_NUM, OPT_AE_MAX_POS);
	free_all_space(&adeconfig_options[0][0], CONFIG_NUM, OPT_ADEC_MAX_POS);
	free_all_space(&aoconfig_options[0][0], CONFIG_NUM, OPT_AO_MAX_POS);

	memset(vsconfig_options,0,sizeof(vsconfig_options));
	memset(asconfig_options,0,sizeof(asconfig_options));
	memset(veconfig_options,0,sizeof(veconfig_options));
	memset(aeconfig_options,0,sizeof(aeconfig_options));
	memset(adeconfig_options,0,sizeof(adeconfig_options));
	memset(aoconfig_options,0,sizeof(aoconfig_options));

	//video encoder instances 
	free_all_space(&ve_instances[0][0],CONFIG_NUM,VE_INST_MAX);
	memset(ve_instances,0,sizeof(ve_instances));
#endif

	return 0;
}
//tranform from struct datatype to string char 
char *cmp_and_cpy(char **dst, const char *src)
{
	int len = 0;

	if(*dst == NULL && src == NULL)
		return NULL;
	else if(*dst != NULL && src == NULL)
	{
		free(*dst);
		*dst = NULL;
	}
	else if((*dst==NULL&&src!=NULL) || strcmp(*dst,src))
	{
		len = strlen(src);
		*dst = (char *)realloc(*dst,len+1);
		strcpy(*dst,src);
	}

	return *dst;
}

int search_matchtoken_pos(char *array[], int size, int elem_num, const char *token, int token_pos)
{
	int i,id;
	
	for(i=0;i<size;i++)
	{
		if(!strcmp(token,*(array+i*elem_num+token_pos)))
		{
			id = i;
			break;
		}
	}
	if(i >= size)
	{
		DBG("the token [%s] is invalid!\n",token);
		return -1;
	}

	return id;
}

int transform_vsstruct_array(struct tt__VideoSourceConfiguration *pvs, char *array[], int size)
{
	if(pvs == NULL || array == NULL || size > VS_MAX_POS)
		return -1;

	cmp_and_cpy(array+VS_NAME, pvs->Name);
	snprintf(buff,BUF_LEN,"%d",pvs->UseCount);
	cmp_and_cpy(array+VS_USECOUNT,buff);
	cmp_and_cpy(array+VS_TOKEN,pvs->token);
	cmp_and_cpy(array+VS_SRCTOKEN,pvs->SourceToken);
	
	snprintf(buff,BUF_LEN,"%d;%d;%d;%d;",
			pvs->Bounds->x, pvs->Bounds->y,pvs->Bounds->width,pvs->Bounds->height);
	cmp_and_cpy(array+VS_BOUNDS,buff);

	snprintf(buff,BUF_LEN,"%d",pvs->__size);
	cmp_and_cpy(array+VS_ANYSIZE,buff);
	cmp_and_cpy(array+VS_ANY, pvs->__any);
	cmp_and_cpy(array+VS_ANYATTR, pvs->__anyAttribute);
	
	return 0;
}

int transform_vostruct_array(struct tt__VideoOutputConfiguration*pvo, char *array[], int size)
{
	if(pvo == NULL || array==NULL || size > VO_MAX_POS)
		return -1;

	cmp_and_cpy(array+VO_NAME,pvo->Name);
	snprintf(buff,BUF_LEN,"%d",pvo->UseCount);
	cmp_and_cpy(array+VO_USECOUNT, buff);
	cmp_and_cpy(array+VO_TOKEN,pvo->token);
	cmp_and_cpy(array+VO_OPTOKEN,pvo->OutputToken);
	
	snprintf(buff,BUF_LEN,"%d",pvo->__size);
	cmp_and_cpy(array+VO_ANYSIZE,buff);
	cmp_and_cpy(array+VO_ANY, pvo->__any);
	cmp_and_cpy(array+VO_ANYATTR, pvo->__anyAttribute);
	
	return 0;
}

int transform_asstruct_array(struct tt__AudioSourceConfiguration*pas, char *array[], int size)
{
	if(pas == NULL || array==NULL || size > AS_MAX_POS)
		return -1;
	
	cmp_and_cpy(array+AS_NAME, pas->Name);
	snprintf(buff,BUF_LEN,"%d",pas->UseCount);
	cmp_and_cpy(array+AS_USECOUNT,buff);
	cmp_and_cpy(array+AS_TOKEN,pas->token);
	cmp_and_cpy(array+AS_SRCTOKEN,pas->SourceToken);
	
	snprintf(buff,BUF_LEN,"%d",pas->__size);
	cmp_and_cpy(array+AS_ANYSIZE,buff);
	cmp_and_cpy(array+AS_ANY, pas->__any);
	cmp_and_cpy(array+AS_ANYATTR, pas->__anyAttribute);

	return 0;
}

int transform_aostruct_array(struct tt__AudioOutputConfiguration*pao, char *array[], int size)
{
	if(pao == NULL ||array ==  NULL || size > AO_MAX_POS)
		return -1;

	cmp_and_cpy(array+AO_NAME,pao->Name);
	snprintf(buff,BUF_LEN,"%d",pao->UseCount);
	cmp_and_cpy(array+AO_USECOUNT, buff);
	cmp_and_cpy(array+AO_TOKEN,pao->token);
	cmp_and_cpy(array+AO_OPTOKEN,pao->OutputToken);
	cmp_and_cpy(array+AO_SNDPRI, pao->SendPrimacy);
	snprintf(buff,BUF_LEN,"\t%d;\t//output level\n",pao->OutputLevel);
	cmp_and_cpy(array+AO_OPLEVL,buff);
	
	snprintf(buff,BUF_LEN,"%d",pao->__size);
	cmp_and_cpy(array+AO_ANYSIZE,buff);
	cmp_and_cpy(array+AO_ANY, pao->__any);
	cmp_and_cpy(array+AO_ANYATTR, pao->__anyAttribute);
	
	return 0;
}

int transform_vestruct_array(struct tt__VideoEncoderConfiguration*pve, char *array[], int size)
{
	if(pve == NULL || array == NULL || size > VE_MAX_POS)
		return -1;

	cmp_and_cpy(array+VE_NAME,pve->Name);
	snprintf(buff,BUF_LEN,"%d",pve->UseCount);
	cmp_and_cpy(array+VE_USECOUNT, buff);
	cmp_and_cpy(array+VE_TOKEN,pve->token);

	snprintf(buff,BUF_LEN,"%d",pve->Encoding);
	cmp_and_cpy(array+VE_ENCODE, buff);
	snprintf(buff,BUF_LEN,"%d;%d;",pve->Resolution->Width,pve->Resolution->Height);
	cmp_and_cpy(array+VE_RESOL, buff);
	snprintf(buff,BUF_LEN,"%f",pve->Quality);
	cmp_and_cpy(array+VE_QUALITY, buff);
	snprintf(buff,BUF_LEN,"%d;%d;%d;",pve->RateControl->FrameRateLimit,
			pve->RateControl->EncodingInterval,pve->RateControl->BitrateLimit);
	cmp_and_cpy(array+VE_RATE, buff);
	if(pve->MPEG4 != NULL)
	{
		snprintf(buff,BUF_LEN,"%d;%d;",pve->MPEG4->GovLength,pve->MPEG4->Mpeg4Profile);
		cmp_and_cpy(array+VE_MPEG4, buff);
	}
	else 
	{
		cmp_and_cpy(array+VE_MPEG4, NULL);
	}
	if(pve->H264 != NULL)
	{
		snprintf(buff,BUF_LEN, "%d;%d;",pve->H264->GovLength,pve->H264->H264Profile);
		cmp_and_cpy(array+VE_H264, buff);
	}
	else 
	{
		cmp_and_cpy(array+VE_H264,NULL);
	}
	snprintf(buff,BUF_LEN,"%s,%s;%d;%d;%s;%d;",pve->Multicast->Address->Type?"ipv6":"ipv4",
			pve->Multicast->Address->IPv4Address,
			pve->Multicast->Port,pve->Multicast->TTL,
			pve->Multicast->AutoStart?"true":"false",
			pve->Multicast->__size);
	cmp_and_cpy(array+VE_MULTICAST, buff);
	snprintf(buff,BUF_LEN,"%ld", pve->SessionTimeout);
	cmp_and_cpy(array+VE_SESSTIME, buff);

	snprintf(buff,BUF_LEN,"%d",pve->__size);
	cmp_and_cpy(array+VE_ANYSIZE,buff);
	cmp_and_cpy(array+VE_ANY, pve->__any);
	cmp_and_cpy(array+VE_ANYATTR, pve->__anyAttribute);
	
	return 0;
}

int transform_aestruct_array(struct tt__AudioEncoderConfiguration*pae, char *array[], int size)
{
	if(pae == NULL || array == NULL || size > AE_MAX_POS)
		return -1;

	cmp_and_cpy(array+AE_NAME,pae->Name);
	snprintf(buff,BUF_LEN,"%d",pae->UseCount);
	cmp_and_cpy(array+AE_USECOUNT, buff);
	cmp_and_cpy(array+AE_TOKEN,pae->token);

	snprintf(buff,BUF_LEN,"%d",pae->Encoding);
	cmp_and_cpy(array+AE_ENCODE, buff);

	snprintf(buff,BUF_LEN,"%d",pae->Bitrate);
	cmp_and_cpy(array+AE_BITRATE, buff);
	snprintf(buff,BUF_LEN,"%d",pae->SampleRate);
	cmp_and_cpy(array+AE_SAMRATE, buff);

	snprintf(buff,BUF_LEN,"%s,%s;%d;%d;%s;%d;",pae->Multicast->Address->Type?"ipv6":"ipv4",
			pae->Multicast->Address->IPv4Address,
			pae->Multicast->Port,pae->Multicast->TTL,
			pae->Multicast->AutoStart?"true":"false",
			pae->Multicast->__size);
	cmp_and_cpy(array+AE_MULTICAST, buff);
	snprintf(buff,BUF_LEN,"%ld", pae->SessionTimeout);
	cmp_and_cpy(array+AE_SESSTIME, buff);

	snprintf(buff,BUF_LEN,"%d",pae->__size);
	cmp_and_cpy(array+AE_ANYSIZE,buff);
	cmp_and_cpy(array+AE_ANY, pae->__any);
	cmp_and_cpy(array+AE_ANYATTR, pae->__anyAttribute);
	return 0;
}

int transform_adecstruct_array(struct tt__AudioDecoderConfiguration*padec, char *array[], int size)
{
	if(padec == NULL || array == NULL || size > ADEC_MAX_POS)
		return -1;

	cmp_and_cpy(array+ADEC_NAME,padec->Name);
	snprintf(buff,BUF_LEN,"%d",padec->UseCount);
	cmp_and_cpy(array+ADEC_USECOUNT, buff);
	cmp_and_cpy(array+ADEC_TOKEN,padec->token);

	snprintf(buff,BUF_LEN,"%d",padec->__size);
	cmp_and_cpy(array+ADEC_ANYSIZE,buff);
	cmp_and_cpy(array+ADEC_ANY, padec->__any);
	cmp_and_cpy(array+ADEC_ANYATTR, padec->__anyAttribute);
	return 0;
}

int transform_vastruct_array(struct tt__VideoAnalyticsConfiguration*pva, char *array[], int size)
{
	if(pva == NULL || array == NULL || size > VA_MAX_POS)
		return -1;

	cmp_and_cpy(array+VA_NAME,pva->Name);
	snprintf(buff,BUF_LEN,"%d",pva->UseCount);
	cmp_and_cpy(array+VA_USECOUNT, buff);
	cmp_and_cpy(array+VA_TOKEN,pva->token);

	// pva->AnalyticsEngineConfiguration ...need to complete more
	snprintf(buff,BUF_LEN,"%d;AnalyticsModules;",pva->AnalyticsEngineConfiguration->__sizeAnalyticsModule);
	cmp_and_cpy(array+VA_AECONF, buff);
	// pva->RuleEngineConfiguration ...need to complete more
	snprintf(buff,BUF_LEN,"%d;Rules;",pva->RuleEngineConfiguration->__sizeRule);
	cmp_and_cpy(array+VA_RECONF,buff);

	snprintf(buff,BUF_LEN,"%d",pva->__size);
	cmp_and_cpy(array+VA_ANYSIZE,buff);
	cmp_and_cpy(array+VA_ANY, pva->__any);
	cmp_and_cpy(array+VA_ANYATTR, pva->__anyAttribute);
	return 0;
}

int transform_metastruct_array(struct tt__MetadataConfiguration*pmeta, char *array[], int size)
{
	if(pmeta == NULL || array == NULL || size > META_MAX_POS)
		return -1;

	cmp_and_cpy(array+META_NAME,pmeta->Name);
	snprintf(buff,BUF_LEN,"%d",pmeta->UseCount);
	cmp_and_cpy(array+META_USECOUNT, buff);
	cmp_and_cpy(array+META_TOKEN,pmeta->token);

	// PTZStatus
	if(pmeta->PTZStatus != NULL)
	{
		snprintf(buff,BUF_LEN, "%d;%d;", pmeta->PTZStatus->Status, pmeta->PTZStatus->Position);
		cmp_and_cpy(array+META_PTZSTAT,buff);
	}
	else
		cmp_and_cpy(array+META_PTZSTAT,NULL);

	// Events
	if(pmeta->Events != NULL)
	{
		int filter_size = pmeta->Events->Filter ? -1:pmeta->Events->Filter->__size;
		int policy_size = pmeta->Events->SubscriptionPolicy ? -1:pmeta->Events->SubscriptionPolicy->__size;
		snprintf(buff,BUF_LEN, "%d;%d;%d;",filter_size,policy_size,pmeta->Events->__size);
		cmp_and_cpy(array+META_EVENT, buff);
	}
	else
		cmp_and_cpy(array+META_EVENT, NULL);

	if(pmeta->Analytics != NULL)
	{
		snprintf(buff,BUF_LEN,"%d", *pmeta->Analytics);
		cmp_and_cpy(array+META_ANALY, buff);
	}
	else
		cmp_and_cpy(array+META_ANALY, NULL);

	snprintf(buff,BUF_LEN,"%s,%s;%d;%d;%s;%d;",pmeta->Multicast->Address->Type?"ipv6":"ipv4",
			pmeta->Multicast->Address->IPv4Address,
			pmeta->Multicast->Port,pmeta->Multicast->TTL,
			pmeta->Multicast->AutoStart?"true":"false",
			pmeta->Multicast->__size);
	cmp_and_cpy(array+META_MULTICAST, buff);
	snprintf(buff,BUF_LEN,"%ld", pmeta->SessionTimeout);
	cmp_and_cpy(array+META_SESSTIME, buff);

	snprintf(buff,BUF_LEN,"%d",pmeta->__size);
	cmp_and_cpy(array+META_ANYSIZE,buff);
	cmp_and_cpy(array+META_ANY, pmeta->__any);
	cmp_and_cpy(array+META_ANYATTR, pmeta->__anyAttribute);
	return 0;
}

int transform_profilestruct_array(struct tt__Profile*profile, char *array[], int size)
{
	if(profile==NULL || array==NULL || size > PF_MAX_POS)
		return -1;

	cmp_and_cpy(array+PF_NAME, profile->Name);
	cmp_and_cpy(array+PF_TOKEN,profile->token);
	snprintf(buff,BUF_LEN,"%s",*profile->fixed?"true":"false");
	cmp_and_cpy(array+PF_FIXED,buff);
	if(profile->VideoSourceConfiguration != NULL)
		cmp_and_cpy(array+PF_VSTOKEN,profile->VideoSourceConfiguration->token);
	else
		cmp_and_cpy(array+PF_VSTOKEN,NULL);
	if(profile->AudioSourceConfiguration != NULL)
		cmp_and_cpy(array+PF_ASTOKEN,profile->AudioSourceConfiguration->token);
	else
		cmp_and_cpy(array+PF_ASTOKEN,NULL);
	if(profile->VideoEncoderConfiguration != NULL)
		cmp_and_cpy(array+PF_VETOKEN,profile->VideoEncoderConfiguration->token);
	else
		cmp_and_cpy(array+PF_VETOKEN,NULL);
	if(profile->AudioEncoderConfiguration != NULL)
		cmp_and_cpy(array+PF_AETOKEN,profile->AudioEncoderConfiguration->token);
	else
		cmp_and_cpy(array+PF_AETOKEN,NULL);
	if(profile->VideoAnalyticsConfiguration != NULL)
		cmp_and_cpy(array+PF_VATOKEN,profile->VideoAnalyticsConfiguration->token);
	else
		cmp_and_cpy(array+PF_VATOKEN,NULL);
	if(profile->PTZConfiguration != NULL)
		cmp_and_cpy(array+PF_PTZTOKEN,profile->PTZConfiguration->token);
	else
		cmp_and_cpy(array+PF_PTZTOKEN,NULL);
	if(profile->MetadataConfiguration != NULL)
		cmp_and_cpy(array+PF_MDTOKEN, profile->MetadataConfiguration->token);
	else
		cmp_and_cpy(array+PF_MDTOKEN,NULL);
	if(profile->Extension != NULL)
	{
		if(profile->Extension->AudioOutputConfiguration != NULL)
			cmp_and_cpy(array+PF_AOTOKEN,profile->Extension->AudioOutputConfiguration->token);
		else
			cmp_and_cpy(array+PF_AOTOKEN,NULL);
		if(profile->Extension->AudioDecoderConfiguration != NULL)
			cmp_and_cpy(array+PF_ADTOKEN,profile->Extension->AudioDecoderConfiguration->token);
		else
			cmp_and_cpy(array+PF_ADTOKEN,NULL);
	}
	else
	{
		cmp_and_cpy(array+PF_AOTOKEN,NULL);
		cmp_and_cpy(array+PF_ADTOKEN,NULL);
	}

	return 0;
}


/*-----------------------------------------------------------------------------*/
/*-----------------------------------------------------------------------------*/
int initiate_rtsp_stream(char multicast_flag, char rtp_protocol)
{
	// setup rtsp live media stream.
	// may deliver the params to rtsp-server(live555) to setup
	return 0;
}

int get_mediaservice_cap(struct soap*soap,struct trt__Capabilities *media)
{
	if(soap == NULL || media == NULL)
	{
		DBG("invalid params.\n");
		return -1;
	}
	media->ProfileCapabilities = (struct trt__ProfileCapabilities *)soap_malloc(soap, sizeof(struct trt__ProfileCapabilities));
	media->StreamingCapabilities = (struct trt__StreamingCapabilities *)soap_malloc(soap, sizeof(struct trt__StreamingCapabilities));
	media->__size = 0;
	media->__any = NULL;
	media->__anyAttribute =NULL;
	media->ProfileCapabilities->__size = 0;
	media->ProfileCapabilities->__any = NULL;
	media->ProfileCapabilities->__anyAttribute =NULL;
	media->ProfileCapabilities->MaximumNumberOfProfiles = (int*)soap_malloc(soap,sizeof(int));
	*media->ProfileCapabilities->MaximumNumberOfProfiles = media_caps[MAX_PROFILES_NUM];
	media->StreamingCapabilities->__size = 0;
	media->StreamingCapabilities->__any = NULL;
	media->StreamingCapabilities->__anyAttribute = NULL;
	media->StreamingCapabilities->RTPMulticast = (enum xsd__boolean*)soap_malloc(soap, sizeof(int));
	media->StreamingCapabilities->RTP_USCORETCP = (enum xsd__boolean*)soap_malloc(soap, sizeof(int));
	media->StreamingCapabilities->RTP_USCORERTSP_USCORETCP = (enum xsd__boolean*)soap_malloc(soap, sizeof(int));
	media->StreamingCapabilities->NonAggregateControl = (enum xsd__boolean*)soap_malloc(soap, sizeof(int));
	*media->StreamingCapabilities->RTPMulticast = media_caps[RTP_MULTICAST]; 
	*media->StreamingCapabilities->RTP_USCORETCP = media_caps[RTP_TCP]; 
	*media->StreamingCapabilities->RTP_USCORERTSP_USCORETCP = media_caps[RTP_RTSP_TCP];
	*media->StreamingCapabilities->NonAggregateControl = media_caps[NON_AGGRE_CONTROL]; 
	return 0;
}

static int search_profiletoken_pos(const char *token)
{
	if(token == NULL)
		return -1;

	int pos = 0;
	pos = search_matchtoken_pos(&profiles[0][0],profile_num,PF_MAX_POS,token,PF_TOKEN);

	return pos;
}

int search_vstoken_pos(const char *token)
{
	if(token == NULL)
		return -1;

	int pos = 0;
	pos = search_matchtoken_pos(&vs_configurations[0][0],vs_config_num,VS_MAX_POS,token,VS_TOKEN);

	return pos;
}

int search_astoken_pos(const char *token)
{
	if(token == NULL)
		return -1;

	int pos = 0;
	pos = search_matchtoken_pos(&as_configurations[0][0],as_config_num,AS_MAX_POS,token,AS_TOKEN);

	return pos;
}

int search_votoken_pos(const char *token)
{
	if(token == NULL)
		return -1;

	int pos = 0;
	pos = search_matchtoken_pos(&vo_configurations[0][0],vo_config_num,VO_MAX_POS,token,VO_TOKEN);

	return pos;
}

int search_aotoken_pos(const char *token)
{
	if(token == NULL)
		return -1;

	int pos = 0;
	pos = search_matchtoken_pos(&ao_configurations[0][0],ao_config_num,AO_MAX_POS,token,AO_TOKEN);

	return pos;
}

static int search_vetoken_pos(const char *token)
{
	if(token == NULL)
		return -1;

	int pos = 0;
	pos = search_matchtoken_pos(&ve_configurations[0][0],ve_config_num,VE_MAX_POS,token,VE_TOKEN);

	return pos;
}

static int search_aetoken_pos(const char *token)
{
	if(token == NULL)
		return -1;

	int pos = 0;
	pos = search_matchtoken_pos(&ae_configurations[0][0],ae_config_num,AE_MAX_POS,token,AE_TOKEN);

	return pos;
}

static int search_adectoken_pos(const char *token)
{
	if(token == NULL)
		return -1;

	int pos = 0;
	pos = search_matchtoken_pos(&adec_configurations[0][0],adec_config_num,ADEC_MAX_POS,token,ADEC_TOKEN);

	return pos;
}

static int search_vatoken_pos(const char *token)
{
	if(token == NULL)
		return -1;

	int pos = 0;
	pos = search_matchtoken_pos(&va_configurations[0][0],va_config_num,VA_MAX_POS,token,VA_TOKEN);

	return pos;
}

static int search_metatoken_pos(const char *token)
{
	if(token == NULL)
		return -1;

	int pos = 0;
	pos = search_matchtoken_pos(&meta_configurations[0][0],meta_config_num,META_MAX_POS,token,META_TOKEN);

	return pos;
}

static int search_ptztoken_pos(const char *token)
{
	if(token == NULL)
		return -1;

	int pos = 0;
	//pos = search_matchtoken_pos(&ptz_configurations[0][0],ptz_config_num,PTZ_MAX_POS,token,PTZ_TOKEN);

	return pos;
}

static char *get_rtsp_uri(const char *token, struct tt__StreamSetup *stream_setup)
{
	int id = 0;

	id = search_profiletoken_pos(token);
	
	if(id < 0)
		return NULL;

	char is_multicast = stream_setup->Stream;// RTP_Unicast=0, RTP_Multicast=1
	char rtp_protocol = stream_setup->Transport->Protocol;//UDP=0,TCP=1,RTSP=2,HTTP=3
	initiate_rtsp_stream(is_multicast,rtp_protocol);

	return rtsp_uri[id];
}

static char *get_snapshot_uri(const char *token)
{
	int id = 0;
	
	id = search_profiletoken_pos(token);
	
	if(id < 0)
		return NULL;

	return snapshot_uri[id];
}


int get_videosource_config(struct soap *soap,int id, struct tt__VideoSourceConfiguration *vs_config)
{
	if(id<0 || vs_config == NULL)
	{
		DBG("param is invalid.\n");
		return -1;
	}

	/* VideoSourceConfiguration */
	vs_config->Name = (char *)soap_malloc(soap,sizeof(char)*TOKEN_LEN);
	vs_config->token = (char *)soap_malloc(soap,sizeof(char)*TOKEN_LEN);
	vs_config->SourceToken = (char *)soap_malloc(soap,sizeof(char)*TOKEN_LEN);
	vs_config->Bounds = (struct tt__IntRectangle *)soap_malloc(soap,sizeof(struct tt__IntRectangle));
	
	/*注意SourceToken*/
	strcpy(vs_config->Name,vs_configurations[id][VS_NAME]);
	strcpy(vs_config->token,vs_configurations[id][VS_TOKEN]);
	/*必须与__tmd__GetVideoSources中的token相同*/
	strcpy(vs_config->SourceToken,vs_configurations[id][VS_SRCTOKEN]);
	vs_config->UseCount = atoi(vs_configurations[id][VS_USECOUNT]);
	sscanf(vs_configurations[id][VS_BOUNDS],"%d;%d;%d;%d;",
			&vs_config->Bounds->x,&vs_config->Bounds->y,
			&vs_config->Bounds->width,&vs_config->Bounds->height);

	vs_config->__size = atoi(vs_configurations[id][VS_ANYSIZE]);
	vs_config->__any = NULL;
	vs_config->__anyAttribute = NULL;

	return 0;
}

int get_audiosource_config(struct soap *soap,int id, struct tt__AudioSourceConfiguration *as_config)
{
	if(id<0 || as_config == NULL)
	{
		DBG("param is invalid.\n");
		return -1;
	}

	as_config->Name = (char *)soap_malloc(soap, sizeof(char)*TOKEN_LEN);
	as_config->token = (char *)soap_malloc(soap, sizeof(char)*TOKEN_LEN);
	as_config->SourceToken = (char *)soap_malloc(soap,sizeof(char)*TOKEN_LEN);

	strncpy(as_config->Name, as_configurations[id][AS_NAME], TOKEN_LEN);
	strncpy(as_config->token, as_configurations[id][AS_TOKEN], TOKEN_LEN);
	strncpy(as_config->SourceToken, as_configurations[id][AS_SRCTOKEN], TOKEN_LEN);
	as_config->UseCount = atoi(as_configurations[id][AS_USECOUNT]);
	as_config->__size = 0;
	as_config->__any = NULL;
	as_config->__anyAttribute = NULL;

	return 0;
}

static int get_multicast_config(struct soap *soap,const char *params, struct tt__MulticastConfiguration*config)
{
	char tmp[16]={0};

	if(params == NULL || config == NULL)
	{
		DBG("invalid params!\n");
		return -1;
	}

	config->Address = (struct tt__IPAddress *)soap_malloc(soap, sizeof(struct tt__IPAddress));
	sscanf(params,"%[^,]",tmp);
	config->Address->Type = strcmp(tmp,"ipv6")?0:1;
	config->Address->IPv4Address = NULL;
	config->Address->IPv6Address = NULL;
	if(!strcmp(tmp,"ipv4"))
	{
		config->Address->IPv4Address = (char *)soap_malloc(soap, sizeof(char)*IPv4_LEN);
		sscanf(params,"%*[^,],%[^;];%d;%d;%[^;];%d;",
			config->Address->IPv4Address,&config->Port,
			&config->TTL,tmp,&config->__size);
	}
	else
	{
		config->Address->IPv4Address = (char *)soap_malloc(soap, sizeof(char)*IPv6_LEN);
		sscanf(params,"%*[^,],%[^;];%d;%d;%[^;];%d;",
			config->Address->IPv6Address,&config->Port,
			&config->TTL,tmp,&config->__size);
	}

	config->AutoStart = strcmp(tmp,"true")?0:1;
	config->__any = NULL;
	config->__anyAttribute = NULL;

	return 0;
}

static int get_videoencoder_config(struct soap *soap,int id,struct tt__VideoEncoderConfiguration *ve_config)
{
	if(id<0 || ve_config == NULL)
	{
		DBG("param is invalid.\n");
		return -1;
	}

	ve_config->Name = (char *)soap_malloc(soap,sizeof(char)*TOKEN_LEN);
	ve_config->token= (char *)soap_malloc(soap,sizeof(char)*TOKEN_LEN);
	strcpy(ve_config->Name,ve_configurations[id][VE_NAME]);
	strcpy(ve_config->token,ve_configurations[id][VE_TOKEN]);
	ve_config->UseCount = atoi(ve_configurations[id][VE_USECOUNT]);
	ve_config->Quality = atoi(ve_configurations[id][VE_QUALITY]);
	ve_config->Encoding = atoi(ve_configurations[id][VE_ENCODE]);
	/*
	if(!strcmp(ve_configurations[id][VE_ENCODE],"MPEG4"))
		ve_config->Encoding = 1;//JPEG = 0, MPEG4 = 1, H264 = 2;
	else
		ve_config->Encoding = strcmp(ve_configurations[id][VE_ENCODE],"H264")?0:2;
	*/
	ve_config->Resolution =(struct tt__VideoResolution *)soap_malloc(soap,sizeof(struct tt__VideoResolution));
	sscanf(ve_configurations[id][VE_RESOL],"%d;%d;",&ve_config->Resolution->Width,&ve_config->Resolution->Height);
	ve_config->RateControl = (struct tt__VideoRateControl *)soap_malloc(soap, sizeof(struct tt__VideoRateControl));
	sscanf(ve_configurations[id][VE_RATE],"%d;%d;%d;",&ve_config->RateControl->FrameRateLimit,&ve_config->RateControl->EncodingInterval,&ve_config->RateControl->BitrateLimit);

	/*可选，可以不设置*/
	char *p;
	//char tmp[16];
	ve_config->MPEG4 = NULL;
	ve_config->H264 = NULL;
	if(p = ve_configurations[id][VE_MPEG4])
	{
		ve_config->MPEG4 = (struct tt__Mpeg4Configuration *)soap_malloc(soap, sizeof(struct tt__Mpeg4Configuration));
		sscanf(p,"%d;%d;",&ve_config->MPEG4->GovLength,&ve_config->MPEG4->Mpeg4Profile);
		//sscanf(p,"%d;%[^;]",&ve_config->MPEG4->GovLength,tmp);
		//ve_config->MPEG4->Mpeg4Profile = strcmp(tmp,"SP")?1:0;
	}
	else if(p = ve_configurations[id][VE_H264])
	{
		ve_config->H264 = (struct tt__H264Configuration *)soap_malloc(soap, sizeof(struct tt__H264Configuration));
		sscanf(p,"%d;%d;",&ve_config->H264->GovLength,&ve_config->H264->H264Profile);
	}

	ve_config->Multicast = (struct tt__MulticastConfiguration *)soap_malloc(soap, sizeof(struct tt__MulticastConfiguration));
	get_multicast_config(soap,ve_configurations[id][VE_MULTICAST], ve_config->Multicast);

	ve_config->SessionTimeout = atoll(ve_configurations[id][VE_SESSTIME]);
	//__size=0,no any elements, if not, should allocate space for any elements.
	ve_config->__size = atoi(ve_configurations[id][VE_ANYSIZE]);
	ve_config->__any = ve_configurations[id][VE_ANY];
	ve_config->__anyAttribute = ve_configurations[id][VE_ANYATTR];

	return 0;
}

static int get_audioencoder_config(struct soap *soap,int id,struct tt__AudioEncoderConfiguration *ae_config)
{
	if(id < 0 || ae_config == NULL)
	{
		DBG("param is invalid.\n");
		return -1;
	}

	ae_config->Name = (char *)soap_malloc(soap,sizeof(char)*TOKEN_LEN);
	ae_config->token= (char *)soap_malloc(soap,sizeof(char)*TOKEN_LEN);
	strcpy(ae_config->Name,ae_configurations[id][AE_NAME]);
	strcpy(ae_config->token,ae_configurations[id][AE_TOKEN]);
	ae_config->UseCount = atoi(ae_configurations[id][AE_USECOUNT]);
	ae_config->Encoding = atoi(ae_configurations[id][AE_ENCODE]);
	ae_config->Bitrate = atoi(ae_configurations[id][AE_BITRATE]);
	ae_config->SampleRate = atoi(ae_configurations[id][AE_SAMRATE]);
	
	ae_config->Multicast = (struct tt__MulticastConfiguration *)soap_malloc(soap, sizeof(struct tt__MulticastConfiguration));
	get_multicast_config(soap,ae_configurations[id][AE_MULTICAST], ae_config->Multicast);

	ae_config->SessionTimeout = atoll(ae_configurations[id][AE_SESSTIME]);

	ae_config->__size = 0;
	ae_config->__any = NULL;
	ae_config->__anyAttribute = NULL;

	return 0;
}

static int get_audiodecoder_config(struct soap *soap,int id,struct tt__AudioDecoderConfiguration *adec_config)
{
	if(id<0 || adec_config == NULL)
	{
		DBG("invalid params!\n");
		return -1;
	}

	adec_config->Name = (char *)soap_malloc(soap,sizeof(char)*TOKEN_LEN);
	adec_config->token= (char *)soap_malloc(soap,sizeof(char)*TOKEN_LEN);
	strcpy(adec_config->Name,adec_configurations[id][ADEC_NAME]);
	strcpy(adec_config->token,adec_configurations[id][ADEC_TOKEN]);
	adec_config->UseCount = atoi(adec_configurations[id][ADEC_USECOUNT]);
	
	adec_config->__size = 0;
	adec_config->__any = NULL;
	adec_config->__anyAttribute = NULL;

	return 0;
}

static int get_videoanalytics_config(struct soap *soap,int id, struct tt__VideoAnalyticsConfiguration *va_config)
{
	if(id<0 || va_config == NULL)
	{
		DBG("param is invalid.\n");
		return -1;
	}

	return 0;
}

static int get_ptz_config(struct soap *soap,int id,struct tt__PTZConfiguration *ptz_config)
{
	if(id<0 || ptz_config == NULL)
	{
		DBG("param is invalid.\n");
		return -1;
	}

	return 0;
}

static int get_metadata_config(struct soap *soap,int id,struct tt__MetadataConfiguration *md_config)
{
	if(id<0 || md_config == NULL)
	{
		DBG("param is invalid.\n");
		return -1;
	}

	return 0;
}

int get_videoutput_config(struct soap *soap,int id,struct tt__VideoOutputConfiguration *vo_config)
{
	if(id<0 || vo_config == NULL)
	{
		DBG("invalid params!\n");
		return -1;
	}

	vo_config->Name = (char *)soap_malloc(soap, sizeof(char)*TOKEN_LEN);
	strcpy(vo_config->Name, vo_configurations[id][VO_NAME]);
	vo_config->UseCount = atoi(vo_configurations[id][VO_USECOUNT]);
	vo_config->token = (char *)soap_malloc(soap, sizeof(char)*TOKEN_LEN);
	strcpy(vo_config->token,vo_configurations[id][VO_TOKEN]);
	vo_config->OutputToken = (char *)soap_malloc(soap, sizeof(char)*TOKEN_LEN);
	strcpy(vo_config->OutputToken,vo_configurations[id][VO_OPTOKEN]);
	vo_config->__size = atoi(vo_configurations[id][VO_ANYSIZE]);
	vo_config->__any = NULL;
	vo_config->__anyAttribute = NULL;
	return 0;
}

int get_audioutput_config(struct soap *soap,int id,struct tt__AudioOutputConfiguration*ao_config)
{
	if(id < 0 || ao_config == NULL)
	{
		DBG("invalid params!\n");
		return -1;
	}

	ao_config->Name = (char *)soap_malloc(soap, sizeof(char)*TOKEN_LEN);
	strcpy(ao_config->Name, ao_configurations[id][AO_NAME]);
	ao_config->UseCount = atoi(ao_configurations[id][AO_USECOUNT]);
	ao_config->token = (char *)soap_malloc(soap, sizeof(char)*TOKEN_LEN);
	strcpy(ao_config->token,ao_configurations[id][AO_TOKEN]);
	ao_config->OutputToken = (char *)soap_malloc(soap, sizeof(char)*TOKEN_LEN);
	strcpy(ao_config->OutputToken,ao_configurations[id][AO_OPTOKEN]);
	ao_config->SendPrimacy = (char *)soap_malloc(soap, sizeof(char)*XADDR_LEN);
	strcpy(ao_config->SendPrimacy, ao_configurations[id][AO_SNDPRI]);
	ao_config->OutputLevel = atoi(ao_configurations[id][AO_OPLEVL]);
	ao_config->__size = atoi(ao_configurations[id][AO_ANYSIZE]);
	ao_config->__any = NULL;
	ao_config->__anyAttribute = NULL;
	return 0;
}

static int get_extension_config(struct soap *soap,const char *token, struct tt__ProfileExtension *ext_config)
{
	if(token == NULL || ext_config == NULL)
	{
		DBG("param is invalid.\n");
		return -1;
	}
	return 0;
}

//get the configuration options intended for 'cfg_token' and compatible for
//'profile_token'.
//if 'profile_token' equals NULL, select the options without compatible
//consideration.
//a without compatible consideration options set is a superset of some profile
//compatible options sets.
static int get_options_id(const char *cfg_token, const char *cfg_token_list,
		const char *profile_token, const char *profile_token_list, char *flag)
{
	if(cfg_token != NULL && strstr(cfg_token_list, cfg_token) == NULL)
	{
		return -1;
	}
	if(profile_token != NULL && strstr(profile_token_list, profile_token) != NULL)
	{
		return 0;
	}
	else if(profile_token != NULL && strstr(profile_token_list, "*") == NULL)
	{
		if(*flag == 0) *flag = 1;
		return -1;
	}
	else if(profile_token == NULL && strstr(profile_token_list, "*") == NULL)
	{
		return 0;
	}

	return -1;
}

int get_aoconfig_options(struct soap *soap, const char *ao_token,const char *profile_token, struct tt__AudioOutputConfigurationOptions*ao_options)
{
	if(soap == NULL || ao_options == NULL)
	{
		DBG("invalid params!\n");
		return -1;
	}

	int id = -1, i, ret;
	int cnt = 0;
	char **p = NULL;
	char *q = NULL;
	int sota_size = 0,sspa_size = 0;
	int size = aoconfig_options_num;
	char flag = 0;

	for(i=0;i<size;i++)
	{
		ret = get_options_id(ao_token, aoconfig_options[i][OPT_AO_AOCLIST],
				profile_token,aoconfig_options[i][OPT_AO_PCMPLIST],&flag);
		if(ret == 0)
		{
			id = i;
			break;
		}
		else if(flag == 1)
		{
			id = i;
			continue;
		}
	}
	if(id < 0 || id >= size)
		id = size - 1;

	ao_options->__sizeOutputTokensAvailable = sota_size = atoi(aoconfig_options[id][OPT_AO_SOTA]);
	ao_options->OutputTokensAvailable = (char **)soap_malloc(soap, sizeof(char *)*sota_size);
	p = ao_options->OutputTokensAvailable;
	q = aoconfig_options[id][OPT_AO_OTS];
	for(i=0;i<sota_size&&p;i++)
	{
		q += cnt;
		p[i] = (char *)soap_malloc(soap, sizeof(char)*TOKEN_LEN);

		sscanf(q, "%[^;];%n", p[i],&cnt);
	}

	ao_options->__sizeSendPrimacyOptions = sspa_size = atoi(aoconfig_options[id][OPT_AO_SSPA]);
	ao_options->SendPrimacyOptions = (char**)soap_malloc(soap, sizeof(char*)*sspa_size);
	p = ao_options->SendPrimacyOptions;
	q = aoconfig_options[id][OPT_AO_SSPA];
	cnt = 0;
	for(i=0;i<sspa_size;i++)
	{
		q += cnt;
		p[i] = (char*)soap_malloc(soap, sizeof(char)*TOKEN_LEN);
		sscanf(q, "%[^;];%n", p[i],&cnt);
	}

	ao_options->OutputLevelRange = (struct tt__IntRange *)soap_malloc(soap, sizeof(struct tt__IntRange));
	sscanf(aoconfig_options[id][OPT_AO_OLR], "%d,%d;",
			&ao_options->OutputLevelRange->Min,
			&ao_options->OutputLevelRange->Max);

	ao_options->__size = atoi(aoconfig_options[id][OPT_AO_ANYSIZE]);
	ao_options->__any = NULL;
	ao_options->__anyAttribute = NULL;

	return 0;
}

int get_voconfig_options(struct soap *soap, const char *token, struct tt__VideoOutputConfigurationOptions *vo_options)
{
	if(token == NULL || vo_options == NULL)
	{
		DBG("invalid params!\n");
		return -1;
	}

	vo_options->__size = 0;
	vo_options->__any = NULL;
	vo_options->__anyAttribute = NULL;

	return 0;
}
int get_asconfig_options(struct soap *soap, const char *as_token, const char *profile_token,struct tt__AudioSourceConfigurationOptions*as_options)
{
	if(soap == NULL || as_options == NULL)
	{
		DBG("invalid params!\n");
		return -1;
	}

	int id = -1,num, i,ret;
	int size = asconfig_options_num;
	char flag = 0;

	for(i=0;i<size;i++)
	{
		ret = get_options_id(as_token,asconfig_options[i][OPT_AS_ASCLIST],
				profile_token,asconfig_options[i][OPT_AS_PCMPLIST],&flag);
		if(ret == 0)
		{
			id = i;
			break;
		}
		else if(flag == 1)
		{
			id = i;
			continue;
		}
	}
	if(id < 0 || id >= size)
		id = size - 1;

	as_options->__sizeInputTokensAvailable = num = atoi(asconfig_options[id][OPT_AS_SITA]);

	if(num > 0)
		as_options->InputTokensAvailable = (char **)soap_malloc(soap, sizeof(char*)*num);
	else
		as_options->InputTokensAvailable = NULL;

	char buff[512]={0};
	memcpy(buff,asconfig_options[id][OPT_AS_ITALIST],512);
	char **p = as_options->InputTokensAvailable;
	char *q = buff;
	char *saveptr;
	for(i=0;i<num&&p;i++,q=NULL)
	{
		p[i] = (char*)soap_malloc(soap, sizeof(char)*TOKEN_LEN);
		strcpy(p[i], strtok_r(q,";", &saveptr));
	}

	as_options->Extension = NULL;
	as_options->__anyAttribute = NULL;

	return 0;
}

int get_vsconfig_options(struct soap *soap, const char *vs_token, const char *profile_token,struct tt__VideoSourceConfigurationOptions*vs_options)
{
	if(soap == NULL || vs_options == NULL)
	{
		DBG("invalid params!\n");
		return -1;
	}

	int id = -1, i,ret;
	int size = vsconfig_options_num; 
	char flag = 0;

	for(i=0;i<size;i++)
	{
		ret = get_options_id(vs_token,vsconfig_options[i][OPT_VS_VSCLIST],
				profile_token,vsconfig_options[i][OPT_VS_PCMPLIST], &flag);
		if(ret == 0)
		{
			id = i;
			break;
		}
		else if(flag == 1)
		{
			id = i;
			continue;
		}
	}
	if(id < 0 || id >= size)
		id = size - 1;

	vs_options->BoundsRange = (struct tt__IntRectangleRange *)soap_malloc(soap, sizeof(struct tt__IntRectangleRange));
	vs_options->BoundsRange->XRange = (struct tt__IntRange *)soap_malloc(soap, sizeof(struct tt__IntRange));
	vs_options->BoundsRange->YRange = (struct tt__IntRange *)soap_malloc(soap, sizeof(struct tt__IntRange));
	vs_options->BoundsRange->WidthRange = (struct tt__IntRange *)soap_malloc(soap, sizeof(struct tt__IntRange));
	vs_options->BoundsRange->HeightRange = (struct tt__IntRange *)soap_malloc(soap, sizeof(struct tt__IntRange));
	sscanf(vsconfig_options[id][OPT_VS_BRANGE], "%d,%d;%d,%d;%d,%d;%d,%d;",
			&vs_options->BoundsRange->XRange->Min,&vs_options->BoundsRange->XRange->Max,
			&vs_options->BoundsRange->YRange->Min,&vs_options->BoundsRange->YRange->Max,
			&vs_options->BoundsRange->WidthRange->Min,&vs_options->BoundsRange->WidthRange->Max,
			&vs_options->BoundsRange->HeightRange->Min,&vs_options->BoundsRange->HeightRange->Max);

	vs_options->__sizeVideoSourceTokensAvailable = size = atoi(vsconfig_options[id][OPT_VS_SVSTA]);
	vs_options->VideoSourceTokensAvailable = (char **)soap_malloc(soap, sizeof(char*)*size);
	int cnt = 0;
	char **p = vs_options->VideoSourceTokensAvailable;
	char *q = vsconfig_options[id][OPT_VS_VSTAS];
	for(i=0;i<size&&p;i++)
	{
		q += cnt;
		p[i] = (char *)soap_malloc(soap, sizeof(char)*TOKEN_LEN);
		memset(p[i], 0, TOKEN_LEN);
		sscanf(q, "%[^;];%n", p[i], &cnt);
	}

	vs_options->Extension = NULL;
	vs_options->__anyAttribute = NULL;

	return 0;
}


int get_veconfig_options(struct soap *soap, const char *ve_token, const char *profile_token,struct tt__VideoEncoderConfigurationOptions *ve_options)
{
	if(soap == NULL || ve_options == NULL)
	{
		DBG("invalid params!\n");
		return -1;
	}

	int id = -1, i,ret;
	int size = veconfig_options_num; 
	char flag = 0;

	for(i=0;i<size;i++)
	{
		ret = get_options_id(ve_token,veconfig_options[i][OPT_VE_VECLIST],
				profile_token,veconfig_options[i][OPT_VE_PCMPLIST], &flag);
		if(ret == 0)
		{
			id = i;
			break;
		}
		else if(flag == 1)
		{
			id = i;
			continue;
		}
	}
	if(id < 0 || id >= size)
		id = size - 1;

	ve_options->QualityRange = (struct tt__IntRange *)soap_malloc(soap, sizeof(struct tt__IntRange));
	ve_options->JPEG = NULL;
	ve_options->H264 = NULL;
	ve_options->MPEG4 = NULL;

	sscanf(veconfig_options[id][OPT_VE_QRANGE],"%d,%d;",&ve_options->QualityRange->Min,&ve_options->QualityRange->Max);

	int res_size = 0,profile_size = 0;
	int cnt = 0;
	char *p = NULL;
	//JPEG options
	p = veconfig_options[id][OPT_VE_JPEG];
	if(p != NULL)
	{
		ve_options->JPEG = (struct tt__JpegOptions *)soap_malloc(soap, sizeof(struct tt__JpegOptions));
		sscanf(p,"%d;%n",&res_size,&cnt);
		ve_options->JPEG->__sizeResolutionsAvailable = res_size;
		ve_options->JPEG->ResolutionsAvailable = (struct tt__VideoResolution *)soap_malloc(soap,sizeof(struct tt__VideoResolution)*res_size);
		p += cnt;
		for(i=0;i<res_size;i++)
		{
			sscanf(p,"%d,%d;%n",&ve_options->JPEG->ResolutionsAvailable->Width,
					&ve_options->JPEG->ResolutionsAvailable->Height,&cnt);
			p += cnt;
		}
		ve_options->JPEG->FrameRateRange = (struct tt__IntRange *)soap_malloc(soap, sizeof(struct tt__IntRange));
		sscanf(p,"%d,%d;%n",&ve_options->JPEG->FrameRateRange->Min,&ve_options->JPEG->FrameRateRange->Max,&cnt);
		p += cnt;
		ve_options->JPEG->EncodingIntervalRange = (struct tt__IntRange *)soap_malloc(soap, sizeof(struct tt__IntRange));
		sscanf(p,"%d,%d;",&ve_options->JPEG->EncodingIntervalRange->Min,&ve_options->JPEG->EncodingIntervalRange->Max);
	}

	//MPEG4 options
	p = veconfig_options[id][OPT_VE_MPEG];
	if(p != NULL)
	{
		ve_options->MPEG4 = (struct tt__Mpeg4Options *)soap_malloc(soap,sizeof(struct tt__Mpeg4Options));
		sscanf(p,"%d;%n",&res_size,&cnt);
		ve_options->MPEG4->__sizeResolutionsAvailable = res_size;
		ve_options->MPEG4->ResolutionsAvailable = (struct tt__VideoResolution *)soap_malloc(soap,sizeof(struct tt__VideoResolution)*res_size);
		p += cnt;
		for(i=0;i<res_size;i++)
		{
			sscanf(p,"%d,%d;%n",&ve_options->MPEG4->ResolutionsAvailable->Width,
					&ve_options->MPEG4->ResolutionsAvailable->Height,&cnt);
			p += cnt;
		}
		ve_options->MPEG4->GovLengthRange = (struct tt__IntRange *)soap_malloc(soap, sizeof(struct tt__IntRange));
		sscanf(p,"%d,%d;%n",&ve_options->MPEG4->GovLengthRange->Min,&ve_options->MPEG4->GovLengthRange->Max,&cnt);
		p += cnt;
		ve_options->MPEG4->FrameRateRange = (struct tt__IntRange *)soap_malloc(soap, sizeof(struct tt__IntRange));
		sscanf(p,"%d,%d;%n",&ve_options->MPEG4->FrameRateRange->Min,&ve_options->MPEG4->FrameRateRange->Max,&cnt);
		p += cnt;
		ve_options->MPEG4->EncodingIntervalRange = (struct tt__IntRange *)soap_malloc(soap, sizeof(struct tt__IntRange));
		sscanf(p,"%d,%d;",&ve_options->MPEG4->EncodingIntervalRange->Min,&ve_options->MPEG4->EncodingIntervalRange->Max,&cnt);
		p += cnt;
		sscanf(p,"%d;%n",&profile_size,&cnt);
		p += cnt;
		ve_options->MPEG4->__sizeMpeg4ProfilesSupported = profile_size;
		ve_options->MPEG4->Mpeg4ProfilesSupported = (enum tt__Mpeg4Profile *)soap_malloc(soap,sizeof(enum tt__Mpeg4Profile)*profile_size);
		for(i=0;i<profile_size;i++)
		{
			sscanf(p,"%d;%n",ve_options->MPEG4->Mpeg4ProfilesSupported+i,&cnt);
			p += cnt;
		}
	}

	//H264 options
	p = veconfig_options[id][OPT_VE_H264];
	if(p != NULL)
	{
		ve_options->H264 = (struct tt__H264Options *)soap_malloc(soap, sizeof(struct tt__H264Options));
		sscanf(p,"%d;%n",&res_size,&cnt);
		ve_options->H264->__sizeResolutionsAvailable = res_size;
		ve_options->H264->ResolutionsAvailable = (struct tt__VideoResolution *)soap_malloc(soap,sizeof(struct tt__VideoResolution)*res_size);
		p += cnt;
		for(i=0;i<res_size;i++)
		{
			sscanf(p,"%d,%d;%n",&ve_options->H264->ResolutionsAvailable->Width,
					&ve_options->H264->ResolutionsAvailable->Height,&cnt);
			p += cnt;
		}
		ve_options->H264->GovLengthRange = (struct tt__IntRange *)soap_malloc(soap, sizeof(struct tt__IntRange));
		sscanf(p,"%d,%d;%n",&ve_options->H264->GovLengthRange->Min,&ve_options->H264->GovLengthRange->Max,&cnt);
		p += cnt;
		ve_options->H264->FrameRateRange = (struct tt__IntRange *)soap_malloc(soap, sizeof(struct tt__IntRange));
		sscanf(p,"%d,%d;%n",&ve_options->H264->FrameRateRange->Min,&ve_options->H264->FrameRateRange->Max,&cnt);
		p += cnt;
		ve_options->H264->EncodingIntervalRange = (struct tt__IntRange *)soap_malloc(soap, sizeof(struct tt__IntRange));
		sscanf(p,"%d,%d;",&ve_options->H264->EncodingIntervalRange->Min,&ve_options->H264->EncodingIntervalRange->Max,&cnt);
		p += cnt;
		sscanf(p,"%d;%n",&profile_size,&cnt);
		p += cnt;
		ve_options->H264->__sizeH264ProfilesSupported = profile_size;
		ve_options->H264->H264ProfilesSupported = (enum tt__H264Profile *)soap_malloc(soap,sizeof(enum tt__H264Profile)*profile_size);
		for(i=0;i<profile_size;i++)
		{
			sscanf(p,"%d;%n",ve_options->H264->H264ProfilesSupported+i,&cnt);
			p += cnt;
		}
	}
	
	ve_options->Extension = NULL;
	ve_options->__anyAttribute = NULL;

	return 0;
}

static int get_intlist(struct soap *soap, char *buff, struct tt__IntList *list)
{
	if(buff == NULL || list == NULL)
	{
		DBG("invalid params!\n");
		return -1;
	}

	int size = 0,cnt = 0,i;
	char *q = NULL;
	char *item = NULL,*saveptr = NULL;

	sscanf(buff,"%d,%n", &size,&cnt);
	list->__sizeItems = size;
	list->Items = (int *)soap_malloc(soap,sizeof(int)*size);
	for(i=0,q=buff+cnt;i<size;i++,q = NULL)
	{
		item = strtok_r(q,",",&saveptr);
		if(item != NULL)
		{
			list->Items[i] = atoi(item);
		}
		else
			break;
	}

	return 0;
}

static int get_audioencoder_option(struct soap *soap, char *opt_params,struct tt__AudioEncoderConfigurationOption *option)
{
	if(opt_params == NULL || option == NULL)
	{
		DBG("invalid params!\n");
		return -1;
	}
	char *p = opt_params;
	char buff[128]={0};
	int cnt = 0;

	sscanf(p,"%d;%n", &option->Encoding,&cnt);
	option->BitrateList = (struct tt__IntList *)soap_malloc(soap, sizeof(struct tt__IntList));
	option->SampleRateList = (struct tt__IntList *)soap_malloc(soap, sizeof(struct tt__IntList));

	p += cnt;
	sscanf(p,"%[^;];%n",buff,&cnt);
	get_intlist(soap, buff, option->BitrateList);

	p += cnt; 
	memset(buff,0,sizeof(buff));
	sscanf(p,"%[^;];%n", buff,&cnt);
	get_intlist(soap, buff, option->SampleRateList);

	option->__size = 0;
	option->__any = NULL;
	option->__anyAttribute = NULL;

	return 0;
}

int get_aeconfig_options(struct soap *soap, const char *ae_token, const char *profile_token,struct tt__AudioEncoderConfigurationOptions *ae_options)
{
	if(soap == NULL || ae_options == NULL)
	{
		DBG("invalid params!\n");
		return -1;
	}

	int id = -1, i,ret;
	int size = aeconfig_options_num; 
	char flag = 0;

	for(i=0;i<size;i++)
	{
		ret = get_options_id(ae_token,aeconfig_options[i][OPT_AE_AECLIST],
				profile_token,aeconfig_options[i][OPT_AE_PCMPLIST], &flag);
		if(ret == 0)
		{
			id = i;
			break;
		}
		else if(flag == 1)
		{
			id = i;
			continue;
		}
	}
	if(id < 0 || id >= size)
		id = size - 1;

	int opt_size = 0;
	ae_options->__sizeOptions = opt_size = atoi(aeconfig_options[id][OPT_AE_SIZE]);
	ae_options->__anyAttribute = NULL;
	ae_options->Options = (struct tt__AudioEncoderConfigurationOption *)soap_malloc(soap,sizeof(struct tt__AudioEncoderConfigurationOption)*opt_size);

	i = -1;
	if(aeconfig_options[id][OPT_AE_G711] != NULL && ++i < opt_size)
		get_audioencoder_option(soap, aeconfig_options[id][OPT_AE_G711],ae_options->Options+i);
	if(aeconfig_options[id][OPT_AE_G726] != NULL && ++i < opt_size)
		get_audioencoder_option(soap, aeconfig_options[id][OPT_AE_G726],ae_options->Options+i);
	if(aeconfig_options[id][OPT_AE_AAC] != NULL && ++i < opt_size)
		get_audioencoder_option(soap, aeconfig_options[id][OPT_AE_AAC],ae_options->Options+i);

	return 0;
}

static int get_audiodec_option(struct soap *soap, char *params, struct tt__G711DecOptions *dec_option)
{
	if(params == NULL || dec_option == NULL)
	{
		DBG("invalid params!\n");
		return -1;
	}

	char *p = params;
	int cnt = 0;
	char buff[128]={0};

	dec_option->Bitrate = (struct tt__IntList *)soap_malloc(soap, sizeof(struct tt__IntList));
	sscanf(p,"%[^;];%n", buff,&cnt);
	get_intlist(soap, buff,dec_option->Bitrate);
	p += cnt;
	dec_option->SampleRateRange = (struct tt__IntList *)soap_malloc(soap, sizeof(struct tt__IntList));
	sscanf(p,"%[^;];%n", buff,&cnt);
	get_intlist(soap, buff,dec_option->SampleRateRange);
	
	dec_option->__size = 0;
	dec_option->__any = NULL;
	dec_option->__anyAttribute = NULL;

	return 0;
}

int get_adeconfig_options(struct soap *soap, const char *adec_token, const char *profile_token,struct tt__AudioDecoderConfigurationOptions *adec_options)
{
	if(soap == NULL || adec_options == NULL)
	{
		DBG("invalid params!\n");
		return -1;
	}

	int id = -1, i,ret;
	int size = adeconfig_options_num; 
	char flag = 0;

	for(i=0;i<size;i++)
	{
		ret = get_options_id(adec_token,adeconfig_options[i][OPT_ADEC_ADECLIST],
				profile_token,adeconfig_options[i][OPT_ADEC_PCMPLIST], &flag);
		if(ret == 0)
		{
			id = i;
			break;
		}
		else if(flag == 1)
		{
			id = i;
			continue;
		}
	}
	if(id < 0 || id >= size)
		id = size - 1;

	if(adeconfig_options[id][OPT_ADEC_AAC] != NULL)
	{
		adec_options->AACDecOptions = (struct tt__AACDecOptions *)soap_malloc(soap,sizeof(struct tt__AACDecOptions));
		get_audiodec_option(soap,adeconfig_options[id][OPT_ADEC_AAC],(struct tt__G711DecOptions *)adec_options->AACDecOptions);
	}
	if(adeconfig_options[id][OPT_ADEC_G711] != NULL)
	{
		adec_options->G711DecOptions = (struct tt__G711DecOptions *)soap_malloc(soap,sizeof(struct tt__G711DecOptions));
		get_audiodec_option(soap,adeconfig_options[id][OPT_ADEC_G711],adec_options->G711DecOptions);
	}
	if(adeconfig_options[id][OPT_ADEC_G726] != NULL)
	{
		adec_options->G726DecOptions = (struct tt__G726DecOptions *)soap_malloc(soap,sizeof(struct tt__G726DecOptions));
		get_audiodec_option(soap,adeconfig_options[id][OPT_ADEC_G726],(struct tt__G711DecOptions *)adec_options->G726DecOptions);
	}

	adec_options->Extension = NULL;
	adec_options->__anyAttribute = NULL;

	return 0;
}

int get_metaconfig_options(struct soap *soap, const char *meta_token, const char *profile_token,struct tt__MetadataConfigurationOptions *meta_options)
{
	if(soap == NULL || meta_options == NULL)
	{
		DBG("invalid params!\n");
		return -1;
	}

	return 0;
}

static int get_profile(struct soap *soap, int id, struct tt__Profile *profile)
{
	int pos = 0;

	if(id < 0||profile == NULL)
	{
		DBG("param is invalid.\n");
		return -1;
	}

	profile->Name = (char *)soap_malloc(soap,sizeof(char)*INFO_LEN);
	profile->token = (char *)soap_malloc(soap,sizeof(char)*TOKEN_LEN);
	profile->fixed = (enum xsd__boolean*)soap_malloc(soap,sizeof(int));
	strcpy(profile->Name, profiles[id][PF_NAME]);
	//snprintf(profile->Name,INFO_LEN,"Profile%d",id);
	strcpy(profile->token,profiles[id][PF_TOKEN]);
	*profile->fixed = strcmp(profiles[id][PF_FIXED],"true")?FALSE:TRUE;
	profile->__anyAttribute = NULL;
	
	profile->VideoSourceConfiguration = NULL;
	profile->VideoEncoderConfiguration = NULL;
	profile->AudioSourceConfiguration = NULL;
	profile->AudioEncoderConfiguration = NULL;
	profile->VideoAnalyticsConfiguration = NULL;
	profile->PTZConfiguration = NULL;
	profile->MetadataConfiguration = NULL;
	profile->Extension = NULL;
	
	/* VideoSourceConfiguration */
	pos = search_vstoken_pos(profiles[id][PF_VSTOKEN]);
	if(pos >= 0)
	{
		profile->VideoSourceConfiguration = (struct tt__VideoSourceConfiguration *)soap_malloc(soap,sizeof(struct tt__VideoSourceConfiguration ));
		get_videosource_config(soap,pos,profile->VideoSourceConfiguration);
	}

	/*VideoEncoderConfiguration*/
	/*必须包含VideoEncoderConfiguration的配置
	不然不会出现live video 和 video streaming*/
	pos = search_vetoken_pos(profiles[id][PF_VETOKEN]);
	if(pos >= 0)
	{
		profile->VideoEncoderConfiguration = (struct tt__VideoEncoderConfiguration *)soap_malloc(soap,sizeof(struct tt__VideoEncoderConfiguration));
		get_videoencoder_config(soap,pos,profile->VideoEncoderConfiguration);
	}

	return 0;
}

static int add_profile_configuration(const char *profile_token,const char *config_token,int config_type_pos)
{
	int matched_profile_pos,len;

	if(config_type_pos >= PF_MAX_POS)
	{
		DBG("invalid configuration type!\n");
		return -1;
	}

	matched_profile_pos = search_profiletoken_pos(profile_token);
	if(matched_profile_pos >= 0)
	{
		len = strlen(config_token);
		if(profiles[matched_profile_pos][config_type_pos]!=NULL)
		{
			free(profiles[matched_profile_pos][config_type_pos]);
		}
		profiles[matched_profile_pos][config_type_pos] = (char *)malloc(len+1);
		strcpy(profiles[matched_profile_pos][config_type_pos],config_token);
	}
	else
	{
		DBG("there is no the profile!\n");
		return -1;
	}

	//write the change to configuration file for persistence
	update_config_default_byarray(CLASS_PROFILE,profile_token,
			profiles[matched_profile_pos], PF_MAX_POS);

	return 0;
}

static int remove_profile_configuration(const char *profile_token,int config_type_pos)
{
	int matched_profile_pos;

	if(config_type_pos >= PF_MAX_POS)
	{
		DBG("invalid configuration type!\n");
		return -1;
	}

	matched_profile_pos = search_profiletoken_pos(profile_token);
	if(matched_profile_pos >= 0)
	{
		if(profiles[matched_profile_pos][config_type_pos]!=NULL)
		{
			free(profiles[matched_profile_pos][config_type_pos]);
			profiles[matched_profile_pos][config_type_pos] = NULL;
		}
	}
	else
	{
		DBG("there is no the profile!\n");
		return -1;
	}

	//write the change to configuration file for persistence
	update_config_default_byarray(CLASS_PROFILE,profile_token,
			profiles[matched_profile_pos], PF_MAX_POS);

	return 0;
}

int set_videosource_config(int persis_flag, struct tt__VideoSourceConfiguration *pconf)
{
	int id = 0;
	id = search_matchtoken_pos(&vs_configurations[0][0],vs_config_num,VS_MAX_POS,
			pconf->token,VS_TOKEN);
	if(id >= 0)
	{
		transform_vsstruct_array(pconf,vs_configurations[id],VS_MAX_POS);
		if(persis_flag)
		{
			update_config_default_byarray(CLASS_VSCFG,pconf->token,vs_configurations[id], VS_MAX_POS);
		}
	}
	else
	{
		DBG("there is no the configuration item!\n");

		//fill soap fault-code
		return -1;
	}

	return 0;
}

int set_audiosource_config(int persis_flag, struct tt__AudioSourceConfiguration*pconf)
{
	int id = 0;
	id = search_matchtoken_pos(&as_configurations[0][0],as_config_num,AS_MAX_POS,
			pconf->token,AS_TOKEN);
	if(id >= 0)
	{
		transform_asstruct_array(pconf,as_configurations[id],AS_MAX_POS);
		if(persis_flag)
		{
			update_config_default_byarray(CLASS_ASCFG,pconf->token,as_configurations[id], AS_MAX_POS);
		}
	}
	else
	{
		DBG("there is no the configuration item!\n");
		//fill soap fault-code
		return -1;
	}

	return 0;
}

int set_audioutput_config(int persis_flag, struct tt__AudioOutputConfiguration *pconf)
{
	int id = 0;
	id = search_matchtoken_pos(&ao_configurations[0][0],ao_config_num,AO_MAX_POS,
			pconf->token,AO_TOKEN);
	if(id >= 0)
	{
		transform_aostruct_array(pconf,ao_configurations[id],AO_MAX_POS);
		if(persis_flag)
		{
			update_config_default_byarray(CLASS_AOCFG,pconf->token,ao_configurations[id], AO_MAX_POS);
		}
	}
	else
	{
		DBG("there is no the configuration item!\n");
		//fill soap fault-code
		return -1;
	}

	return 0;
}

int set_videoutput_config(int persis_flag, struct tt__VideoOutputConfiguration *pconf)
{
	int id = 0;
	id = search_matchtoken_pos(&vo_configurations[0][0],vo_config_num,VO_MAX_POS,
			pconf->token,VO_TOKEN);
	if(id >= 0)
	{
		transform_vostruct_array(pconf,vo_configurations[id],VO_MAX_POS);
		if(persis_flag)
		{
			update_config_default_byarray(CLASS_VOCFG,pconf->token,vo_configurations[id], VO_MAX_POS);
		}
	}
	else
	{
		DBG("there is no the configuration item!\n");
		//fill soap fault-code
		return -1;
	}

	return 0;
}
//=================================================================================================//
/** Auto-test server operation __trt__GetServiceCapabilities */
int __trt__GetServiceCapabilities(struct soap *soap, struct _trt__GetServiceCapabilities *trt__GetServiceCapabilities, struct _trt__GetServiceCapabilitiesResponse *trt__GetServiceCapabilitiesResponse)
{	
	/* Return incomplete response with default data values */
	INFO(stderr);
	trt__GetServiceCapabilitiesResponse->Capabilities = (struct trt__Capabilities *)soap_malloc(soap, sizeof(struct trt__Capabilities));
	get_mediaservice_cap(soap, trt__GetServiceCapabilitiesResponse->Capabilities);
	return SOAP_OK;
}


/** Auto-test server operation __trt__GetVideoSources */
int __trt__GetVideoSources(struct soap *soap, struct _trt__GetVideoSources *trt__GetVideoSources, struct _trt__GetVideoSourcesResponse *trt__GetVideoSourcesResponse)
{	
	/* Return incomplete response with default data values */
	__tmd__GetVideoSources(soap, trt__GetVideoSources, trt__GetVideoSourcesResponse);
	return SOAP_OK;
}


/** Auto-test server operation __trt__GetAudioSources */
int __trt__GetAudioSources(struct soap *soap, struct _trt__GetAudioSources *trt__GetAudioSources, struct _trt__GetAudioSourcesResponse *trt__GetAudioSourcesResponse)
{	
	/* Return incomplete response with default data values */
	__tmd__GetAudioSources(soap, trt__GetAudioSources, trt__GetAudioSourcesResponse);

	return SOAP_OK;
}


/** Auto-test server operation __trt__GetAudioOutputs */
int __trt__GetAudioOutputs(struct soap *soap, struct _trt__GetAudioOutputs *trt__GetAudioOutputs, struct _trt__GetAudioOutputsResponse *trt__GetAudioOutputsResponse)
{	
	/* Return incomplete response with default data values */
	__tmd__GetAudioOutputs(soap, trt__GetAudioOutputs, trt__GetAudioOutputsResponse);

	return SOAP_OK;
}


/** Auto-test server operation __trt__CreateProfile */
int __trt__CreateProfile(struct soap *soap, struct _trt__CreateProfile *trt__CreateProfile, struct _trt__CreateProfileResponse *trt__CreateProfileResponse)
{	
	/* Return incomplete response with default data values */
	INFO(stderr);

	trt__CreateProfileResponse->Profile = (struct tt__Profile *)soap_malloc(soap,sizeof(struct tt__Profile));
	trt__CreateProfileResponse->Profile->Name = (char *)soap_malloc(soap,sizeof(char)*TOKEN_LEN);
	memcpy(trt__CreateProfileResponse->Profile->Name,trt__CreateProfile->Name,TOKEN_LEN);
	trt__CreateProfileResponse->Profile->token = (char *)soap_malloc(soap,sizeof(char)*TOKEN_LEN);
	if(trt__CreateProfile->Token)
	{
		memcpy(trt__CreateProfileResponse->Profile->token,trt__CreateProfile->Token,TOKEN_LEN);
	}
	else //auto generated an unique token
	{
		snprintf(trt__CreateProfileResponse->Profile->token,TOKEN_LEN,"token-%ld",time(NULL));
	}
	trt__CreateProfileResponse->Profile->fixed = (enum xsd__boolean *)soap_malloc(soap,sizeof(enum xsd__boolean));
	*trt__CreateProfileResponse->Profile->fixed = FALSE;

	trt__CreateProfileResponse->Profile->AudioEncoderConfiguration = NULL;
	trt__CreateProfileResponse->Profile->AudioSourceConfiguration = NULL;
	trt__CreateProfileResponse->Profile->Extension = NULL;
	trt__CreateProfileResponse->Profile->MetadataConfiguration = NULL;
	trt__CreateProfileResponse->Profile->PTZConfiguration = NULL;
	trt__CreateProfileResponse->Profile->VideoAnalyticsConfiguration = NULL;
	trt__CreateProfileResponse->Profile->VideoEncoderConfiguration = NULL;
	trt__CreateProfileResponse->Profile->VideoSourceConfiguration = NULL;
	trt__CreateProfileResponse->Profile->__anyAttribute = NULL;

	//add the created profile to onvif configuration file
	insert_config_default(CLASS_PROFILE, trt__CreateProfileResponse->Profile->token, 
			(void*)trt__CreateProfileResponse->Profile, TYPE_PROFILE);
	if(profile_num < CONFIG_NUM)
	{
		transform_profilestruct_array(trt__CreateProfileResponse->Profile,profiles[profile_num++], PF_MAX_POS);
	}
	else
	{
		DBG("the profiles number need to increase!\n");
	}

	return SOAP_OK;
}

/** Auto-test server operation __trt__GetProfile */
int __trt__GetProfile(struct soap *soap, struct _trt__GetProfile *trt__GetProfile, struct _trt__GetProfileResponse *trt__GetProfileResponse)
{	
	/* Return incomplete response with default data values */
	INFO(stderr);
	DBG("trt__GetProfile=%s\n",trt__GetProfile->ProfileToken );

	//但odm单击一个profile时，需要获取，不然不会出现live video和video streaming
	int pos = 0;
	pos = search_profiletoken_pos(trt__GetProfile->ProfileToken);
	if(pos >= 0)
	{
		trt__GetProfileResponse->Profile = (struct tt__Profile *)soap_malloc(soap,sizeof(struct tt__Profile));
		get_profile(soap,pos,trt__GetProfileResponse->Profile);

		return SOAP_OK;
	}
	else
	{
		DBG("profile token [%s] doesnot exist!\n", trt__GetProfile->ProfileToken);
		trt__GetProfileResponse->Profile = NULL;
		//inform SOAP-ENV
		//Code: env:Sender-->ter:InvalidArgVal --> ter:NoProfile 
		//RESA: Profile token does not exist
		//soap_sender_fault(soap,"Profile token does not exist",NULL);
		/*
		const char *spec_err[] = {"ter:NoProfile",NULL};
		soap_sender_fault_subcode(soap,"ter:InvalidArgVal","Profile token does not exist",NULL);
		process_specific_fault(soap,spec_err);
		*/
		process_specific_fault(soap,media_spec_fault_code[TRT_SEND_NOPROFILE]);

		return SOAP_FAULT;
	}
}

/** Auto-test server operation __trt__GetProfiles */
int __trt__GetProfiles(struct soap *soap, struct _trt__GetProfiles *trt__GetProfiles, struct _trt__GetProfilesResponse *trt__GetProfilesResponse)
{	
	/* Return incomplete response with default data values */
	INFO(stderr);

	int i;
	int size = profile_num;

	trt__GetProfilesResponse->Profiles =(struct tt__Profile *)soap_malloc(soap, sizeof(struct tt__Profile) * size);
	trt__GetProfilesResponse->__sizeProfiles = size;

	for(i=0;i<size;i++)
	{
		get_profile(soap,i,trt__GetProfilesResponse->Profiles+i);
	}

	return SOAP_OK;
}


/** Auto-test server operation __trt__AddVideoEncoderConfiguration */
int __trt__AddVideoEncoderConfiguration(struct soap *soap, struct _trt__AddVideoEncoderConfiguration *trt__AddVideoEncoderConfiguration, struct _trt__AddVideoEncoderConfigurationResponse *trt__AddVideoEncoderConfigurationResponse)
{	
	INFO(stderr);

	char *profile_token = trt__AddVideoEncoderConfiguration->ProfileToken;
	char *config_token = trt__AddVideoEncoderConfiguration->ConfigurationToken;

	add_profile_configuration(profile_token,config_token,PF_VETOKEN);

	return SOAP_OK;
}


/** Auto-test server operation __trt__AddVideoSourceConfiguration */
int __trt__AddVideoSourceConfiguration(struct soap *soap, struct _trt__AddVideoSourceConfiguration *trt__AddVideoSourceConfiguration, struct _trt__AddVideoSourceConfigurationResponse *trt__AddVideoSourceConfigurationResponse)
{	
	INFO(stderr);

	char *profile_token = trt__AddVideoSourceConfiguration->ProfileToken;
	char *config_token = trt__AddVideoSourceConfiguration->ConfigurationToken;

	add_profile_configuration(profile_token,config_token,PF_VSTOKEN);

	return SOAP_OK;
}


/** Auto-test server operation __trt__AddAudioEncoderConfiguration */
int __trt__AddAudioEncoderConfiguration(struct soap *soap, struct _trt__AddAudioEncoderConfiguration *trt__AddAudioEncoderConfiguration, struct _trt__AddAudioEncoderConfigurationResponse *trt__AddAudioEncoderConfigurationResponse)
{	
	INFO(stderr);

	char *profile_token = trt__AddAudioEncoderConfiguration->ProfileToken;
	char *config_token = trt__AddAudioEncoderConfiguration->ConfigurationToken;

	add_profile_configuration(profile_token,config_token,PF_AETOKEN);

	return SOAP_OK;
}


/** Auto-test server operation __trt__AddAudioSourceConfiguration */
int __trt__AddAudioSourceConfiguration(struct soap *soap, struct _trt__AddAudioSourceConfiguration *trt__AddAudioSourceConfiguration, struct _trt__AddAudioSourceConfigurationResponse *trt__AddAudioSourceConfigurationResponse)
{	
	INFO(stderr);

	char *profile_token = trt__AddAudioSourceConfiguration->ProfileToken;
	char *config_token = trt__AddAudioSourceConfiguration->ConfigurationToken;

	add_profile_configuration(profile_token,config_token,PF_ASTOKEN);

	return SOAP_OK;
}


/** Auto-test server operation __trt__AddPTZConfiguration */
int __trt__AddPTZConfiguration(struct soap *soap, struct _trt__AddPTZConfiguration *trt__AddPTZConfiguration, struct _trt__AddPTZConfigurationResponse *trt__AddPTZConfigurationResponse)
{	
	INFO(stderr);

	char *profile_token = trt__AddPTZConfiguration->ProfileToken;
	char *config_token = trt__AddPTZConfiguration->ConfigurationToken;

	add_profile_configuration(profile_token,config_token,PF_PTZTOKEN);

	return SOAP_OK;
}


/** Auto-test server operation __trt__AddVideoAnalyticsConfiguration */
int __trt__AddVideoAnalyticsConfiguration(struct soap *soap, struct _trt__AddVideoAnalyticsConfiguration *trt__AddVideoAnalyticsConfiguration, struct _trt__AddVideoAnalyticsConfigurationResponse *trt__AddVideoAnalyticsConfigurationResponse)
{	
	INFO(stderr);

	char *profile_token = trt__AddVideoAnalyticsConfiguration->ProfileToken;
	char *config_token = trt__AddVideoAnalyticsConfiguration->ConfigurationToken;

	add_profile_configuration(profile_token,config_token,PF_VATOKEN);

	return SOAP_OK;
}


/** Auto-test server operation __trt__AddMetadataConfiguration */
int __trt__AddMetadataConfiguration(struct soap *soap, struct _trt__AddMetadataConfiguration *trt__AddMetadataConfiguration, struct _trt__AddMetadataConfigurationResponse *trt__AddMetadataConfigurationResponse)
{	
	INFO(stderr);

	char *profile_token = trt__AddMetadataConfiguration->ProfileToken;
	char *config_token = trt__AddMetadataConfiguration->ConfigurationToken;

	add_profile_configuration(profile_token,config_token,PF_MDTOKEN);

	return SOAP_OK;
}


/** Auto-test server operation __trt__AddAudioOutputConfiguration */
int __trt__AddAudioOutputConfiguration(struct soap *soap, struct _trt__AddAudioOutputConfiguration *trt__AddAudioOutputConfiguration, struct _trt__AddAudioOutputConfigurationResponse *trt__AddAudioOutputConfigurationResponse)
{	
	INFO(stderr);

	char *profile_token = trt__AddAudioOutputConfiguration->ProfileToken;
	char *config_token = trt__AddAudioOutputConfiguration->ConfigurationToken;

	add_profile_configuration(profile_token,config_token,PF_AOTOKEN);

	return SOAP_OK;
}


/** Auto-test server operation __trt__AddAudioDecoderConfiguration */
int __trt__AddAudioDecoderConfiguration(struct soap *soap, struct _trt__AddAudioDecoderConfiguration *trt__AddAudioDecoderConfiguration, struct _trt__AddAudioDecoderConfigurationResponse *trt__AddAudioDecoderConfigurationResponse)
{	
	INFO(stderr);

	char *profile_token = trt__AddAudioDecoderConfiguration->ProfileToken;
	char *config_token = trt__AddAudioDecoderConfiguration->ConfigurationToken;

	add_profile_configuration(profile_token,config_token,PF_ADTOKEN);

	return SOAP_OK;
}


/** Auto-test server operation __trt__RemoveVideoEncoderConfiguration */
int __trt__RemoveVideoEncoderConfiguration(struct soap *soap, struct _trt__RemoveVideoEncoderConfiguration *trt__RemoveVideoEncoderConfiguration, struct _trt__RemoveVideoEncoderConfigurationResponse *trt__RemoveVideoEncoderConfigurationResponse)
{	
	INFO(stderr);

	char *profile_token = trt__RemoveVideoEncoderConfiguration->ProfileToken;

	remove_profile_configuration(profile_token,PF_VETOKEN);

	return SOAP_OK;
}


/** Auto-test server operation __trt__RemoveVideoSourceConfiguration */
int __trt__RemoveVideoSourceConfiguration(struct soap *soap, struct _trt__RemoveVideoSourceConfiguration *trt__RemoveVideoSourceConfiguration, struct _trt__RemoveVideoSourceConfigurationResponse *trt__RemoveVideoSourceConfigurationResponse)
{	
	INFO(stderr);

	char *profile_token = trt__RemoveVideoSourceConfiguration->ProfileToken;

	remove_profile_configuration(profile_token,PF_VSTOKEN);

	return SOAP_OK;
}


/** Auto-test server operation __trt__RemoveAudioEncoderConfiguration */
int __trt__RemoveAudioEncoderConfiguration(struct soap *soap, struct _trt__RemoveAudioEncoderConfiguration *trt__RemoveAudioEncoderConfiguration, struct _trt__RemoveAudioEncoderConfigurationResponse *trt__RemoveAudioEncoderConfigurationResponse)
{	
	INFO(stderr);

	char *profile_token = trt__RemoveAudioEncoderConfiguration->ProfileToken;

	remove_profile_configuration(profile_token,PF_AETOKEN);

	return SOAP_OK;
}


/** Auto-test server operation __trt__RemoveAudioSourceConfiguration */
int __trt__RemoveAudioSourceConfiguration(struct soap *soap, struct _trt__RemoveAudioSourceConfiguration *trt__RemoveAudioSourceConfiguration, struct _trt__RemoveAudioSourceConfigurationResponse *trt__RemoveAudioSourceConfigurationResponse)
{	
	INFO(stderr);

	char *profile_token = trt__RemoveAudioSourceConfiguration->ProfileToken;

	remove_profile_configuration(profile_token,PF_ASTOKEN);

	return SOAP_OK;
}


/** Auto-test server operation __trt__RemovePTZConfiguration */
int __trt__RemovePTZConfiguration(struct soap *soap, struct _trt__RemovePTZConfiguration *trt__RemovePTZConfiguration, struct _trt__RemovePTZConfigurationResponse *trt__RemovePTZConfigurationResponse)
{	
	INFO(stderr);

	char *profile_token = trt__RemovePTZConfiguration->ProfileToken;

	remove_profile_configuration(profile_token,PF_PTZTOKEN);

	return SOAP_OK;
}


/** Auto-test server operation __trt__RemoveVideoAnalyticsConfiguration */
int __trt__RemoveVideoAnalyticsConfiguration(struct soap *soap, struct _trt__RemoveVideoAnalyticsConfiguration *trt__RemoveVideoAnalyticsConfiguration, struct _trt__RemoveVideoAnalyticsConfigurationResponse *trt__RemoveVideoAnalyticsConfigurationResponse)
{	
	INFO(stderr);

	char *profile_token = trt__RemoveVideoAnalyticsConfiguration->ProfileToken;

	remove_profile_configuration(profile_token,PF_VATOKEN);

	return SOAP_OK;
}


/** Auto-test server operation __trt__RemoveMetadataConfiguration */
int __trt__RemoveMetadataConfiguration(struct soap *soap, struct _trt__RemoveMetadataConfiguration *trt__RemoveMetadataConfiguration, struct _trt__RemoveMetadataConfigurationResponse *trt__RemoveMetadataConfigurationResponse)
{	
	INFO(stderr);

	char *profile_token = trt__RemoveMetadataConfiguration->ProfileToken;

	remove_profile_configuration(profile_token,PF_MDTOKEN);

	return SOAP_OK;
}


/** Auto-test server operation __trt__RemoveAudioOutputConfiguration */
int __trt__RemoveAudioOutputConfiguration(struct soap *soap, struct _trt__RemoveAudioOutputConfiguration *trt__RemoveAudioOutputConfiguration, struct _trt__RemoveAudioOutputConfigurationResponse *trt__RemoveAudioOutputConfigurationResponse)
{	
	INFO(stderr);

	char *profile_token = trt__RemoveAudioOutputConfiguration->ProfileToken;

	remove_profile_configuration(profile_token,PF_AOTOKEN);

	return SOAP_OK;
}


/** Auto-test server operation __trt__RemoveAudioDecoderConfiguration */
int __trt__RemoveAudioDecoderConfiguration(struct soap *soap, struct _trt__RemoveAudioDecoderConfiguration *trt__RemoveAudioDecoderConfiguration, struct _trt__RemoveAudioDecoderConfigurationResponse *trt__RemoveAudioDecoderConfigurationResponse)
{	
	INFO(stderr);

	char *profile_token = trt__RemoveAudioDecoderConfiguration->ProfileToken;

	remove_profile_configuration(profile_token,PF_ADTOKEN);

	return SOAP_OK;
}


/** Auto-test server operation __trt__DeleteProfile */
int __trt__DeleteProfile(struct soap *soap, struct _trt__DeleteProfile *trt__DeleteProfile, struct _trt__DeleteProfileResponse *trt__DeleteProfileResponse)
{	
	int matched_profile_pos;
	char fixed_flag = 0;

	matched_profile_pos = search_profiletoken_pos(trt__DeleteProfile->ProfileToken); 
	if(matched_profile_pos >= 0)
	{
		fixed_flag = strcmp(profiles[matched_profile_pos][PF_FIXED],"false")?1:0;
		if(!fixed_flag)
		{
			//free_config_space(profiles[matched_profile_pos],PF_MAX_POS);
			free_all_space(&profiles[0][0], CONFIG_NUM, PF_MAX_POS);
			profile_num -= 1;
			delete_config_default(CLASS_PROFILE, trt__DeleteProfile->ProfileToken);
			query_all_config_default(CLASS_PROFILE,&profiles[0][0],CONFIG_NUM,
					&profile_num, PF_MAX_POS);
		}
		else 
		{
			DBG("the profile is fixed!\n");
			//fill soap fault-code
		}
	}
	else
	{
		DBG("the profile that has the token doesnot exist!\n");
		//fill soap fault-code
	}

	return SOAP_OK;
}


/** Auto-test server operation __trt__GetVideoSourceConfigurations */
int __trt__GetVideoSourceConfigurations(struct soap *soap, struct _trt__GetVideoSourceConfigurations *trt__GetVideoSourceConfigurations, struct _trt__GetVideoSourceConfigurationsResponse *trt__GetVideoSourceConfigurationsResponse)
{	
	/* Return incomplete response with default data values */
	INFO(stderr);
	int size = vs_config_num;
	int i;
	trt__GetVideoSourceConfigurationsResponse->__sizeConfigurations = size;
	trt__GetVideoSourceConfigurationsResponse->Configurations = (struct tt__VideoSourceConfiguration *)soap_malloc(soap, sizeof(struct tt__VideoSourceConfiguration)*size);
	for(i=0;i<size;i++)
	{
		get_videosource_config(soap,i,trt__GetVideoSourceConfigurationsResponse->Configurations+i);
	}

	return SOAP_OK;
}


/** Auto-test server operation __trt__GetVideoEncoderConfigurations */
int __trt__GetVideoEncoderConfigurations(struct soap *soap, struct _trt__GetVideoEncoderConfigurations *trt__GetVideoEncoderConfigurations, struct _trt__GetVideoEncoderConfigurationsResponse *trt__GetVideoEncoderConfigurationsResponse)
{	
	/* Return incomplete response with default data values */
	INFO(stderr);

	int size = ve_config_num,i;
	trt__GetVideoEncoderConfigurationsResponse->__sizeConfigurations = size;
	trt__GetVideoEncoderConfigurationsResponse->Configurations = (struct tt__VideoEncoderConfiguration*)soap_malloc(soap,sizeof(struct tt__VideoEncoderConfiguration)*size);
	for(i=0;i<size;i++)
	{
		get_videoencoder_config(soap,i,trt__GetVideoEncoderConfigurationsResponse->Configurations+i);
	}

	return SOAP_OK;
}


/** Auto-test server operation __trt__GetAudioSourceConfigurations */
int __trt__GetAudioSourceConfigurations(struct soap *soap, struct _trt__GetAudioSourceConfigurations *trt__GetAudioSourceConfigurations, struct _trt__GetAudioSourceConfigurationsResponse *trt__GetAudioSourceConfigurationsResponse)
{	
	/* Return incomplete response with default data values */
	INFO(stderr);

	int size = as_config_num;
	int i;
	trt__GetAudioSourceConfigurationsResponse->__sizeConfigurations = size;
	trt__GetAudioSourceConfigurationsResponse->Configurations = (struct tt__AudioSourceConfiguration*)soap_malloc(soap,sizeof(struct tt__AudioSourceConfiguration)*size);
	for(i=0;i<size;i++)
	{
		get_audiosource_config(soap,i,trt__GetAudioSourceConfigurationsResponse->Configurations + i);
	}

	return SOAP_OK;
}


/** Auto-test server operation __trt__GetAudioEncoderConfigurations */
int __trt__GetAudioEncoderConfigurations(struct soap *soap, struct _trt__GetAudioEncoderConfigurations *trt__GetAudioEncoderConfigurations, struct _trt__GetAudioEncoderConfigurationsResponse *trt__GetAudioEncoderConfigurationsResponse)
{	
	/* Return incomplete response with default data values */
	INFO(stderr);

	int size = ae_config_num;
	int i;
	trt__GetAudioEncoderConfigurationsResponse->__sizeConfigurations = size;
	trt__GetAudioEncoderConfigurationsResponse->Configurations = (struct tt__AudioEncoderConfiguration *)soap_malloc(soap,sizeof(struct tt__AudioEncoderConfiguration)*size);
	for(i=0;i<size;i++)
	{
		get_audioencoder_config(soap,i,trt__GetAudioEncoderConfigurationsResponse->Configurations+i);
	}

	return SOAP_OK;
}


/** Auto-test server operation __trt__GetVideoAnalyticsConfigurations */
int __trt__GetVideoAnalyticsConfigurations(struct soap *soap, struct _trt__GetVideoAnalyticsConfigurations *trt__GetVideoAnalyticsConfigurations, struct _trt__GetVideoAnalyticsConfigurationsResponse *trt__GetVideoAnalyticsConfigurationsResponse)
{	
	/* Return incomplete response with default data values */
	INFO(stderr);

	int size = va_config_num;
	int i;

	trt__GetVideoAnalyticsConfigurationsResponse->__sizeConfigurations = size;
	trt__GetVideoAnalyticsConfigurationsResponse->Configurations = (struct tt__VideoAnalyticsConfiguration *)soap_malloc(soap, sizeof(struct tt__VideoAnalyticsConfiguration)*size);

	for(i=0;i<size;i++)
	{
		get_videoanalytics_config(soap,i,trt__GetVideoAnalyticsConfigurationsResponse->Configurations+i);
	}

	return SOAP_OK;
}


/** Auto-test server operation __trt__GetMetadataConfigurations */
int __trt__GetMetadataConfigurations(struct soap *soap, struct _trt__GetMetadataConfigurations *trt__GetMetadataConfigurations, struct _trt__GetMetadataConfigurationsResponse *trt__GetMetadataConfigurationsResponse)
{	
	/* Return incomplete response with default data values */
	INFO(stderr);

	int size = meta_config_num;
	int i;

	trt__GetMetadataConfigurationsResponse->__sizeConfigurations = size;
	trt__GetMetadataConfigurationsResponse->Configurations = (struct tt__MetadataConfiguration *)soap_malloc(soap, sizeof(struct tt__MetadataConfiguration)*size);
	for(i=0;i<size;i++)
	{
		get_metadata_config(soap,i,trt__GetMetadataConfigurationsResponse->Configurations+i);
	}

	return SOAP_OK;
}


/** Auto-test server operation __trt__GetAudioOutputConfigurations */
int __trt__GetAudioOutputConfigurations(struct soap *soap, struct _trt__GetAudioOutputConfigurations *trt__GetAudioOutputConfigurations, struct _trt__GetAudioOutputConfigurationsResponse *trt__GetAudioOutputConfigurationsResponse)
{	
	/* Return incomplete response with default data values */
	INFO(stderr);

	int size = ao_config_num;
	int i;
	trt__GetAudioOutputConfigurationsResponse->__sizeConfigurations = size;
	trt__GetAudioOutputConfigurationsResponse->Configurations = (struct tt__AudioOutputConfiguration*)soap_malloc(soap, sizeof(struct tt__AudioOutputConfiguration)*size);
	for(i=0;i<size;i++)
	{
		get_audioutput_config(soap,i,trt__GetAudioOutputConfigurationsResponse->Configurations + i);
	}

	return SOAP_OK;
}


/** Auto-test server operation __trt__GetAudioDecoderConfigurations */
int __trt__GetAudioDecoderConfigurations(struct soap *soap, struct _trt__GetAudioDecoderConfigurations *trt__GetAudioDecoderConfigurations, struct _trt__GetAudioDecoderConfigurationsResponse *trt__GetAudioDecoderConfigurationsResponse)
{	
	/* Return incomplete response with default data values */
	INFO(stderr);

	int size = adec_config_num;
	int i;
	trt__GetAudioDecoderConfigurationsResponse->__sizeConfigurations = size;
	trt__GetAudioDecoderConfigurationsResponse->Configurations = (struct tt__AudioDecoderConfiguration *)soap_malloc(soap,sizeof(struct tt__AudioDecoderConfiguration));
	for(i=0;i<size;i++)
	{
		get_audiodecoder_config(soap,i,trt__GetAudioDecoderConfigurationsResponse->Configurations+i);
	}

	return SOAP_OK;
}


/** Auto-test server operation __trt__GetVideoSourceConfiguration */
int __trt__GetVideoSourceConfiguration(struct soap *soap, struct _trt__GetVideoSourceConfiguration *trt__GetVideoSourceConfiguration, struct _trt__GetVideoSourceConfigurationResponse *trt__GetVideoSourceConfigurationResponse)
{	
	/* Return incomplete response with default data values */
	INFO(stderr);

	int pos = 0;
	pos = search_vstoken_pos(trt__GetVideoSourceConfiguration->ConfigurationToken);
	if(pos >= 0)
	{
		trt__GetVideoSourceConfigurationResponse->Configuration = (struct tt__VideoSourceConfiguration *)soap_malloc(soap, sizeof(struct tt__VideoSourceConfiguration));
		get_videosource_config(soap,pos,trt__GetVideoSourceConfigurationResponse->Configuration);
		return SOAP_OK;
	}
	else
	{
		trt__GetVideoSourceConfigurationResponse->Configuration = NULL;
		/*
		const char *spec_err[] = {"ter:NoConfig",NULL};
		soap_sender_fault_subcode(soap,"ter:InvalidArgVal","Configuration token does not exist",NULL);
		process_specific_fault(soap,spec_err);
		*/
		process_specific_fault(soap,media_spec_fault_code[TRT_SEND_NOCONF]);
		return SOAP_FAULT;
	}
}


/** Auto-test server operation __trt__GetVideoEncoderConfiguration */
int __trt__GetVideoEncoderConfiguration(struct soap *soap, struct _trt__GetVideoEncoderConfiguration *trt__GetVideoEncoderConfiguration, struct _trt__GetVideoEncoderConfigurationResponse *trt__GetVideoEncoderConfigurationResponse)
{	
	/* Return incomplete response with default data values */
	INFO(stderr);

	int pos = 0;
	pos = search_vetoken_pos(trt__GetVideoEncoderConfiguration->ConfigurationToken);
	if(pos >= 0)
	{
		trt__GetVideoEncoderConfigurationResponse->Configuration = (struct tt__VideoEncoderConfiguration *)soap_malloc(soap,sizeof(struct tt__VideoEncoderConfiguration));
		get_videoencoder_config(soap,pos,trt__GetVideoEncoderConfigurationResponse->Configuration);
		return SOAP_OK;
	}
	else
	{
		trt__GetVideoEncoderConfigurationResponse->Configuration = NULL;
		return SOAP_FAULT;
	}
}


/** Auto-test server operation __trt__GetAudioSourceConfiguration */
int __trt__GetAudioSourceConfiguration(struct soap *soap, struct _trt__GetAudioSourceConfiguration *trt__GetAudioSourceConfiguration, struct _trt__GetAudioSourceConfigurationResponse *trt__GetAudioSourceConfigurationResponse)
{	
	/* Return incomplete response with default data values */
	INFO(stderr);

	int pos = 0;
	pos = search_astoken_pos(trt__GetAudioSourceConfiguration->ConfigurationToken);
	if(pos >= 0)
	{
		trt__GetAudioSourceConfigurationResponse->Configuration = (struct tt__AudioSourceConfiguration *)soap_malloc(soap, sizeof(struct tt__AudioSourceConfiguration));
		get_audiosource_config(soap,pos,trt__GetAudioSourceConfigurationResponse->Configuration);
		return SOAP_OK;
	}
	else
	{
		trt__GetAudioSourceConfigurationResponse->Configuration = NULL;
		return SOAP_FAULT;
	}
}


/** Auto-test server operation __trt__GetAudioEncoderConfiguration */
int __trt__GetAudioEncoderConfiguration(struct soap *soap, struct _trt__GetAudioEncoderConfiguration *trt__GetAudioEncoderConfiguration, struct _trt__GetAudioEncoderConfigurationResponse *trt__GetAudioEncoderConfigurationResponse)
{	
	/* Return incomplete response with default data values */
	INFO(stderr);

	int pos = 0;
	pos = search_aetoken_pos(trt__GetAudioEncoderConfiguration->ConfigurationToken);
	if(pos >= 0)
	{
		trt__GetAudioEncoderConfigurationResponse->Configuration = (struct tt__AudioEncoderConfiguration *)soap_malloc(soap, sizeof(struct tt__AudioEncoderConfiguration));
		get_audioencoder_config(soap,pos,trt__GetAudioEncoderConfigurationResponse->Configuration);
		return SOAP_OK;
	}
	else
	{
		trt__GetAudioEncoderConfigurationResponse->Configuration = NULL;
		return SOAP_FAULT;
	}
}


/** Auto-test server operation __trt__GetVideoAnalyticsConfiguration */
int __trt__GetVideoAnalyticsConfiguration(struct soap *soap, struct _trt__GetVideoAnalyticsConfiguration *trt__GetVideoAnalyticsConfiguration, struct _trt__GetVideoAnalyticsConfigurationResponse *trt__GetVideoAnalyticsConfigurationResponse)
{	
	/* Return incomplete response with default data values */
	INFO(stderr);

	int pos = 0;
	pos = search_vatoken_pos(trt__GetVideoAnalyticsConfiguration->ConfigurationToken);
	if(pos >= 0)
	{
		trt__GetVideoAnalyticsConfigurationResponse->Configuration = (struct tt__VideoAnalyticsConfiguration *)soap_malloc(soap, sizeof(struct tt__VideoAnalyticsConfiguration));
		get_videoanalytics_config(soap,pos,trt__GetVideoAnalyticsConfigurationResponse->Configuration);
		return SOAP_OK;
	}
	else
	{
		trt__GetVideoAnalyticsConfigurationResponse->Configuration = NULL;
		return SOAP_FAULT;
	}
}


/** Auto-test server operation __trt__GetMetadataConfiguration */
int __trt__GetMetadataConfiguration(struct soap *soap, struct _trt__GetMetadataConfiguration *trt__GetMetadataConfiguration, struct _trt__GetMetadataConfigurationResponse *trt__GetMetadataConfigurationResponse)
{	
	/* Return incomplete response with default data values */
	INFO(stderr);

	int pos = 0;
	pos = search_metatoken_pos(trt__GetMetadataConfiguration->ConfigurationToken);
	if(pos >= 0)
	{
		trt__GetMetadataConfigurationResponse->Configuration = (struct tt__MetadataConfiguration *)soap_malloc(soap, sizeof(struct tt__MetadataConfiguration));
		get_metadata_config(soap,pos,trt__GetMetadataConfigurationResponse->Configuration);
		return SOAP_OK;
	}
	else
	{
		trt__GetMetadataConfigurationResponse->Configuration = NULL;
		return SOAP_FAULT;
	}
}


/** Auto-test server operation __trt__GetAudioOutputConfiguration */
int __trt__GetAudioOutputConfiguration(struct soap *soap, struct _trt__GetAudioOutputConfiguration *trt__GetAudioOutputConfiguration, struct _trt__GetAudioOutputConfigurationResponse *trt__GetAudioOutputConfigurationResponse)
{	
	/* Return incomplete response with default data values */
	INFO(stderr);

	int pos = 0;
	pos = search_aotoken_pos(trt__GetAudioOutputConfiguration->ConfigurationToken);
	if(pos >= 0)
	{
		trt__GetAudioOutputConfigurationResponse->Configuration = (struct tt__AudioOutputConfiguration*)soap_malloc(soap, sizeof(struct tt__AudioOutputConfiguration));
		get_audioutput_config(soap, pos,trt__GetAudioOutputConfigurationResponse->Configuration);

		return SOAP_OK;
	}
	else
	{
		trt__GetAudioOutputConfigurationResponse->Configuration = NULL;
		return SOAP_FAULT;
	}
}


/** Auto-test server operation __trt__GetAudioDecoderConfiguration */
int __trt__GetAudioDecoderConfiguration(struct soap *soap, struct _trt__GetAudioDecoderConfiguration *trt__GetAudioDecoderConfiguration, struct _trt__GetAudioDecoderConfigurationResponse *trt__GetAudioDecoderConfigurationResponse)
{	
	/* Return incomplete response with default data values */
	INFO(stderr);

	int pos = 0;
	pos = search_adectoken_pos(trt__GetAudioDecoderConfiguration->ConfigurationToken);
	if(pos >= 0)
	{
		trt__GetAudioDecoderConfigurationResponse->Configuration = (struct tt__AudioDecoderConfiguration*)soap_malloc(soap,sizeof(struct tt__AudioDecoderConfiguration));
		get_audiodecoder_config(soap,pos,trt__GetAudioDecoderConfigurationResponse->Configuration);
		return SOAP_OK;
	}
	else
	{
		trt__GetAudioDecoderConfigurationResponse->Configuration = NULL;
		return SOAP_FAULT;
	}
}


/** Auto-test server operation __trt__GetCompatibleVideoEncoderConfigurations */
int __trt__GetCompatibleVideoEncoderConfigurations(struct soap *soap, struct _trt__GetCompatibleVideoEncoderConfigurations *trt__GetCompatibleVideoEncoderConfigurations, struct _trt__GetCompatibleVideoEncoderConfigurationsResponse *trt__GetCompatibleVideoEncoderConfigurationsResponse)
{	
	/* Return incomplete response with default data values */
	INFO(stderr);

	int size = 0,i;
	int id[ve_config_num];
	for(i=0;i<ve_config_num;i++)
	{
		if(atoi(ve_configurations[i][VE_PCMPNUM])==0 || strstr(ve_configurations[i][VE_PCMPLIST],trt__GetCompatibleVideoEncoderConfigurations->ProfileToken)!=NULL)
			id[size++] = i;
	}
	trt__GetCompatibleVideoEncoderConfigurationsResponse->__sizeConfigurations = size;
	trt__GetCompatibleVideoEncoderConfigurationsResponse->Configurations = (struct tt__VideoEncoderConfiguration *)soap_malloc(soap, sizeof(struct tt__VideoEncoderConfiguration)*size);
	for(i=0;i<size;i++)
	{
		get_videoencoder_config(soap,id[i],trt__GetCompatibleVideoEncoderConfigurationsResponse->Configurations+i);
	}

	return SOAP_OK;
}


/** Auto-test server operation __trt__GetCompatibleVideoSourceConfigurations */
int __trt__GetCompatibleVideoSourceConfigurations(struct soap *soap, struct _trt__GetCompatibleVideoSourceConfigurations *trt__GetCompatibleVideoSourceConfigurations, struct _trt__GetCompatibleVideoSourceConfigurationsResponse *trt__GetCompatibleVideoSourceConfigurationsResponse)
{	
	/* Return incomplete response with default data values */
	INFO(stderr);

	int size = 0,i;
	int id[vs_config_num];
	for(i=0;i<vs_config_num;i++)
	{
		if(atoi(vs_configurations[i][VS_PCMPNUM]) == 0 || 
			strstr(vs_configurations[i][VS_PCMPLIST],trt__GetCompatibleVideoSourceConfigurations->ProfileToken) != NULL)
			id[size++] = i;
	}
			
	trt__GetCompatibleVideoSourceConfigurationsResponse->__sizeConfigurations = size;
	trt__GetCompatibleVideoSourceConfigurationsResponse->Configurations = (struct tt__VideoSourceConfiguration *)soap_malloc(soap, sizeof(struct tt__VideoSourceConfiguration)*size);
	for(i=0;i<size;i++)
	{
		get_videosource_config(soap,id[i],trt__GetCompatibleVideoSourceConfigurationsResponse->Configurations+i);
	}

	return SOAP_OK;
}


/** Auto-test server operation __trt__GetCompatibleAudioEncoderConfigurations */
int __trt__GetCompatibleAudioEncoderConfigurations(struct soap *soap, struct _trt__GetCompatibleAudioEncoderConfigurations *trt__GetCompatibleAudioEncoderConfigurations, struct _trt__GetCompatibleAudioEncoderConfigurationsResponse *trt__GetCompatibleAudioEncoderConfigurationsResponse)
{	
	/* Return incomplete response with default data values */
	INFO(stderr);

	int size = 0,i;
	int id[ae_config_num];
	for(i=0;i<ae_config_num;i++)
	{
		if(atoi(ae_configurations[i][AE_PCMPNUM])==0 || strstr(ae_configurations[i][AE_PCMPLIST],trt__GetCompatibleAudioEncoderConfigurations->ProfileToken)!=NULL)
			id[size++] = i;
	}
	trt__GetCompatibleAudioEncoderConfigurationsResponse->__sizeConfigurations = size;
	trt__GetCompatibleAudioEncoderConfigurationsResponse->Configurations = (struct tt__AudioEncoderConfiguration *)soap_malloc(soap,sizeof(struct tt__AudioEncoderConfiguration)*size);
	for(i=0;i<size;i++)
	{
		get_audioencoder_config(soap,id[i],trt__GetCompatibleAudioEncoderConfigurationsResponse->Configurations+i);
	}

	return SOAP_OK;
}


/** Auto-test server operation __trt__GetCompatibleAudioSourceConfigurations */
int __trt__GetCompatibleAudioSourceConfigurations(struct soap *soap, struct _trt__GetCompatibleAudioSourceConfigurations *trt__GetCompatibleAudioSourceConfigurations, struct _trt__GetCompatibleAudioSourceConfigurationsResponse *trt__GetCompatibleAudioSourceConfigurationsResponse)
{	
	/* Return incomplete response with default data values */
	INFO(stderr);

	int size = 0,i;
	int id[as_config_num];
	for(i=0;i<as_config_num;i++)
	{
		if(atoi(as_configurations[i][AS_PCMPNUM])==0 || strstr(as_configurations[i][AS_PCMPLIST],trt__GetCompatibleAudioSourceConfigurations->ProfileToken)!=NULL)
			id[size++] = i;
	}
	trt__GetCompatibleAudioSourceConfigurationsResponse->__sizeConfigurations = size;
	trt__GetCompatibleAudioSourceConfigurationsResponse->Configurations = (struct tt__AudioSourceConfiguration *)soap_malloc(soap, sizeof(struct tt__AudioSourceConfiguration)*size);
	for(i=0;i<size;i++)
	{
		get_audiosource_config(soap,id[i],trt__GetCompatibleAudioSourceConfigurationsResponse->Configurations+i);
	}

	return SOAP_OK;
}


/** Auto-test server operation __trt__GetCompatibleVideoAnalyticsConfigurations */
int __trt__GetCompatibleVideoAnalyticsConfigurations(struct soap *soap, struct _trt__GetCompatibleVideoAnalyticsConfigurations *trt__GetCompatibleVideoAnalyticsConfigurations, struct _trt__GetCompatibleVideoAnalyticsConfigurationsResponse *trt__GetCompatibleVideoAnalyticsConfigurationsResponse)
{	
	/* Return incomplete response with default data values */
	INFO(stderr);

	return SOAP_OK;
}


/** Auto-test server operation __trt__GetCompatibleMetadataConfigurations */
int __trt__GetCompatibleMetadataConfigurations(struct soap *soap, struct _trt__GetCompatibleMetadataConfigurations *trt__GetCompatibleMetadataConfigurations, struct _trt__GetCompatibleMetadataConfigurationsResponse *trt__GetCompatibleMetadataConfigurationsResponse)
{	
	/* Return incomplete response with default data values */
	INFO(stderr);

	return SOAP_OK;
}


/** Auto-test server operation __trt__GetCompatibleAudioOutputConfigurations */
int __trt__GetCompatibleAudioOutputConfigurations(struct soap *soap, struct _trt__GetCompatibleAudioOutputConfigurations *trt__GetCompatibleAudioOutputConfigurations, struct _trt__GetCompatibleAudioOutputConfigurationsResponse *trt__GetCompatibleAudioOutputConfigurationsResponse)
{	
	/* Return incomplete response with default data values */
	INFO(stderr);

	int size=0,i;
	int id[ao_config_num];
	for(i=0;i<size;i++)
	{
		if(atoi(ao_configurations[i][AO_PCMPNUM])==0 || strstr(ao_configurations[i][AO_PCMPLIST],trt__GetCompatibleAudioOutputConfigurations->ProfileToken)!=NULL)
			id[size++] = i;
	}
	trt__GetCompatibleAudioOutputConfigurationsResponse->__sizeConfigurations = size;
	trt__GetCompatibleAudioOutputConfigurationsResponse->Configurations = (struct tt__AudioOutputConfiguration *)soap_malloc(soap, sizeof(struct tt__AudioOutputConfiguration)*size);
	for(i=0;i<size;i++)
	{
		get_audioutput_config(soap,id[i],trt__GetCompatibleAudioOutputConfigurationsResponse->Configurations+i);
	}

	return SOAP_OK;
}


/** Auto-test server operation __trt__GetCompatibleAudioDecoderConfigurations */
int __trt__GetCompatibleAudioDecoderConfigurations(struct soap *soap, struct _trt__GetCompatibleAudioDecoderConfigurations *trt__GetCompatibleAudioDecoderConfigurations, struct _trt__GetCompatibleAudioDecoderConfigurationsResponse *trt__GetCompatibleAudioDecoderConfigurationsResponse)
{	
	/* Return incomplete response with default data values */
	INFO(stderr);

	int size=0,i;
	int id[adec_config_num];
	for(i=0;i<size;i++)
	{
		if(atoi(adec_configurations[i][ADEC_PCMPNUM])==0 || strstr(adec_configurations[i][ADEC_PCMPLIST],trt__GetCompatibleAudioDecoderConfigurations->ProfileToken)!=NULL)
			id[size++] = i;
	}
	trt__GetCompatibleAudioDecoderConfigurationsResponse->__sizeConfigurations = size;
	trt__GetCompatibleAudioDecoderConfigurationsResponse->Configurations = (struct tt__AudioDecoderConfiguration *)soap_malloc(soap, sizeof(struct tt__AudioDecoderConfiguration)*size);
	for(i=0;i<size;i++)
	{
		get_audiodecoder_config(soap,id[i],trt__GetCompatibleAudioDecoderConfigurationsResponse->Configurations+i);
	}

	return SOAP_OK;
}


/** Auto-test server operation __trt__SetVideoSourceConfiguration */
int __trt__SetVideoSourceConfiguration(struct soap *soap, struct _trt__SetVideoSourceConfiguration *trt__SetVideoSourceConfiguration, struct _trt__SetVideoSourceConfigurationResponse *trt__SetVideoSourceConfigurationResponse)
{	
	INFO(stderr);

	int persis_flag = trt__SetVideoSourceConfiguration->ForcePersistence;
	DBG("persis_flag = %d\n",persis_flag);
	//update config
	struct tt__VideoSourceConfiguration *pconf = trt__SetVideoSourceConfiguration->Configuration;
	set_videosource_config(persis_flag, pconf);

	return SOAP_OK;
}


/** Auto-test server operation __trt__SetVideoEncoderConfiguration */
int __trt__SetVideoEncoderConfiguration(struct soap *soap, struct _trt__SetVideoEncoderConfiguration *trt__SetVideoEncoderConfiguration, struct _trt__SetVideoEncoderConfigurationResponse *trt__SetVideoEncoderConfigurationResponse)
{	
	INFO(stderr);

	int persis_flag = trt__SetVideoEncoderConfiguration->ForcePersistence;
	DBG("persis_flag = %d.\n",persis_flag);
	int id = 0;
	struct tt__VideoEncoderConfiguration *pconf = trt__SetVideoEncoderConfiguration->Configuration;
	id = search_matchtoken_pos(&ve_configurations[0][0],ve_config_num,VE_MAX_POS,
			pconf->token,VE_TOKEN);
	if(id >= 0)
	{
		transform_vestruct_array(pconf,ve_configurations[id],VE_MAX_POS);
		if(persis_flag)
		{
			update_config_default_byarray(CLASS_VECFG,pconf->token,ve_configurations[id], VE_MAX_POS);
		}
	}
	else
	{
		DBG("there is no the configuration item!\n");
		//fill soap fault-code
	}

	return SOAP_OK;
}


/** Auto-test server operation __trt__SetAudioSourceConfiguration */
int __trt__SetAudioSourceConfiguration(struct soap *soap, struct _trt__SetAudioSourceConfiguration *trt__SetAudioSourceConfiguration, struct _trt__SetAudioSourceConfigurationResponse *trt__SetAudioSourceConfigurationResponse)
{	
	INFO(stderr);

	int persis_flag = trt__SetAudioSourceConfiguration->ForcePersistence;
	DBG("persis_flag = %d\n",persis_flag);
	struct tt__AudioSourceConfiguration*pconf = trt__SetAudioSourceConfiguration->Configuration;
	set_audiosource_config(persis_flag, pconf);

	return SOAP_OK;
}


/** Auto-test server operation __trt__SetAudioEncoderConfiguration */
int __trt__SetAudioEncoderConfiguration(struct soap *soap, struct _trt__SetAudioEncoderConfiguration *trt__SetAudioEncoderConfiguration, struct _trt__SetAudioEncoderConfigurationResponse *trt__SetAudioEncoderConfigurationResponse)
{	
	INFO(stderr);

	int persis_flag = trt__SetAudioEncoderConfiguration->ForcePersistence;
	DBG("persis_flag = %d\n",persis_flag);
	int id = 0;
	struct tt__AudioEncoderConfiguration*pconf = trt__SetAudioEncoderConfiguration->Configuration;
	id = search_matchtoken_pos(&ae_configurations[0][0],ae_config_num,AE_MAX_POS,
			pconf->token,AE_TOKEN);
	if(id >= 0)
	{
		transform_aestruct_array(pconf,ae_configurations[id],AE_MAX_POS);
		if(persis_flag)
		{
			update_config_default_byarray(CLASS_AECFG,pconf->token,ae_configurations[id], AE_MAX_POS);
		}
	}
	else
	{
		DBG("there is no the configuration item!\n");
		//fill soap fault-code
	}

	return SOAP_OK;
}


/** Auto-test server operation __trt__SetVideoAnalyticsConfiguration */
int __trt__SetVideoAnalyticsConfiguration(struct soap *soap, struct _trt__SetVideoAnalyticsConfiguration *trt__SetVideoAnalyticsConfiguration, struct _trt__SetVideoAnalyticsConfigurationResponse *trt__SetVideoAnalyticsConfigurationResponse)
{	
	INFO(stderr);

	int persis_flag = trt__SetVideoAnalyticsConfiguration->ForcePersistence;
	DBG("persis_flag = %d\n",persis_flag);
	int id = 0;
	struct tt__VideoAnalyticsConfiguration*pconf = trt__SetVideoAnalyticsConfiguration->Configuration;
	id = search_matchtoken_pos(&va_configurations[0][0],va_config_num,VA_MAX_POS,
			pconf->token,VA_TOKEN);
	if(id >= 0)
	{
		transform_vastruct_array(pconf,va_configurations[id],VA_MAX_POS);
		if(persis_flag)
		{
			update_config_default_byarray(CLASS_VACFG,pconf->token,va_configurations[id], VA_MAX_POS);
		}
	}
	else
	{
		DBG("there is no the configuration item!\n");
		//fill soap fault-code
	}

	return SOAP_OK;
}


/** Auto-test server operation __trt__SetMetadataConfiguration */
int __trt__SetMetadataConfiguration(struct soap *soap, struct _trt__SetMetadataConfiguration *trt__SetMetadataConfiguration, struct _trt__SetMetadataConfigurationResponse *trt__SetMetadataConfigurationResponse)
{	
	INFO(stderr);

	int persis_flag = trt__SetMetadataConfiguration->ForcePersistence;
	DBG("persis_flag = %d\n",persis_flag);
	int id = 0;
	struct tt__MetadataConfiguration*pconf = trt__SetMetadataConfiguration->Configuration;
	id = search_matchtoken_pos(&meta_configurations[0][0],meta_config_num,META_MAX_POS,
			pconf->token,META_TOKEN);
	if(id >= 0)
	{
		transform_metastruct_array(pconf,meta_configurations[id],META_MAX_POS);
		if(persis_flag)
		{
			update_config_default_byarray(CLASS_METACFG,pconf->token,meta_configurations[id], META_MAX_POS);
		}
	}
	else
	{
		DBG("there is no the configuration item!\n");
		//fill soap fault-code
	}

	return SOAP_OK;
}


/** Auto-test sermetar operation __trt__SetAudioOutputConfiguration */
int __trt__SetAudioOutputConfiguration(struct soap *soap, struct _trt__SetAudioOutputConfiguration *trt__SetAudioOutputConfiguration, struct _trt__SetAudioOutputConfigurationResponse *trt__SetAudioOutputConfigurationResponse)
{	
	INFO(stderr);

	int persis_flag = trt__SetAudioOutputConfiguration->ForcePersistence;
	DBG("persis_flag = %d\n",persis_flag);
	struct tt__AudioOutputConfiguration*pconf = trt__SetAudioOutputConfiguration->Configuration;
	set_audioutput_config(persis_flag, pconf);

	return SOAP_OK;
}


/** Auto-test server operation __trt__SetAudioDecoderConfiguration */
int __trt__SetAudioDecoderConfiguration(struct soap *soap, struct _trt__SetAudioDecoderConfiguration *trt__SetAudioDecoderConfiguration, struct _trt__SetAudioDecoderConfigurationResponse *trt__SetAudioDecoderConfigurationResponse)
{	
	INFO(stderr);

	int persis_flag = trt__SetAudioDecoderConfiguration->ForcePersistence;
	DBG("persis_flag = %d\n",persis_flag);
	int id = 0;
	struct tt__AudioDecoderConfiguration*pconf = trt__SetAudioDecoderConfiguration->Configuration;
	id = search_matchtoken_pos(&adec_configurations[0][0],adec_config_num,ADEC_MAX_POS,
			pconf->token,ADEC_TOKEN);
	if(id >= 0)
	{
		transform_adecstruct_array(pconf,adec_configurations[id],ADEC_MAX_POS);
		if(persis_flag)
		{
			update_config_default_byarray(CLASS_ADECFG,pconf->token,adec_configurations[id], ADEC_MAX_POS);
		}
	}
	else
	{
		DBG("there is no the configuration item!\n");
		//fill soap fault-code
	}
	return SOAP_OK;
}


/** Auto-test server operation __trt__GetVideoSourceConfigurationOptions */
int __trt__GetVideoSourceConfigurationOptions(struct soap *soap, struct _trt__GetVideoSourceConfigurationOptions *trt__GetVideoSourceConfigurationOptions, struct _trt__GetVideoSourceConfigurationOptionsResponse *trt__GetVideoSourceConfigurationOptionsResponse)
{	
	/* Return incomplete response with default data values */
	INFO(stderr);
	trt__GetVideoSourceConfigurationOptionsResponse->Options = (struct tt__VideoSourceConfigurationOptions *)soap_malloc(soap, sizeof(struct tt__VideoSourceConfigurationOptions));
	//intended for vs configuration token, compatible for media profile token.
	get_vsconfig_options(soap,trt__GetVideoSourceConfigurationOptions->ConfigurationToken,
			trt__GetVideoSourceConfigurationOptions->ProfileToken,
			trt__GetVideoSourceConfigurationOptionsResponse->Options);

	return SOAP_OK;
}


/** Auto-test server operation __trt__GetVideoEncoderConfigurationOptions */
int __trt__GetVideoEncoderConfigurationOptions(struct soap *soap, struct _trt__GetVideoEncoderConfigurationOptions *trt__GetVideoEncoderConfigurationOptions, struct _trt__GetVideoEncoderConfigurationOptionsResponse *trt__GetVideoEncoderConfigurationOptionsResponse)
{	
	/* Return incomplete response with default data values */
	INFO(stderr);

	trt__GetVideoEncoderConfigurationOptionsResponse->Options = (struct tt__VideoEncoderConfigurationOptions *)soap_malloc(soap,sizeof(struct tt__VideoEncoderConfigurationOptions));
	get_veconfig_options(soap,trt__GetVideoEncoderConfigurationOptions->ConfigurationToken,
			trt__GetVideoEncoderConfigurationOptions->ProfileToken,
			trt__GetVideoEncoderConfigurationOptionsResponse->Options);

	return SOAP_OK;
}


/** Auto-test server operation __trt__GetAudioSourceConfigurationOptions */
int __trt__GetAudioSourceConfigurationOptions(struct soap *soap, struct _trt__GetAudioSourceConfigurationOptions *trt__GetAudioSourceConfigurationOptions, struct _trt__GetAudioSourceConfigurationOptionsResponse *trt__GetAudioSourceConfigurationOptionsResponse)
{	
	/* Return incomplete response with default data values */
	INFO(stderr);

	trt__GetAudioSourceConfigurationOptionsResponse->Options = (struct tt__AudioSourceConfigurationOptions*)soap_malloc(soap, sizeof(struct tt__AudioSourceConfigurationOptions));
	get_asconfig_options(soap, trt__GetAudioSourceConfigurationOptions->ConfigurationToken,
			trt__GetAudioSourceConfigurationOptions->ProfileToken,
			trt__GetAudioSourceConfigurationOptionsResponse->Options);

	return SOAP_OK;
}


/** Auto-test server operation __trt__GetAudioEncoderConfigurationOptions */
int __trt__GetAudioEncoderConfigurationOptions(struct soap *soap, struct _trt__GetAudioEncoderConfigurationOptions *trt__GetAudioEncoderConfigurationOptions, struct _trt__GetAudioEncoderConfigurationOptionsResponse *trt__GetAudioEncoderConfigurationOptionsResponse)
{	
	/* Return incomplete response with default data values */
	INFO(stderr);

	trt__GetAudioEncoderConfigurationOptionsResponse->Options = (struct tt__AudioEncoderConfigurationOptions *)soap_malloc(soap, sizeof(struct tt__AudioEncoderConfigurationOptions));
	get_aeconfig_options(soap,trt__GetAudioEncoderConfigurationOptions->ConfigurationToken,
			trt__GetAudioEncoderConfigurationOptions->ProfileToken,
			trt__GetAudioEncoderConfigurationOptionsResponse->Options);

	return SOAP_OK;
}


/** Auto-test server operation __trt__GetMetadataConfigurationOptions */
int __trt__GetMetadataConfigurationOptions(struct soap *soap, struct _trt__GetMetadataConfigurationOptions *trt__GetMetadataConfigurationOptions, struct _trt__GetMetadataConfigurationOptionsResponse *trt__GetMetadataConfigurationOptionsResponse)
{	
	/* Return incomplete response with default data values */
	INFO(stderr);

	trt__GetMetadataConfigurationOptionsResponse->Options = (struct tt__MetadataConfigurationOptions *)soap_malloc(soap, sizeof(struct tt__MetadataConfigurationOptions));
	get_metaconfig_options(soap, trt__GetMetadataConfigurationOptions->ConfigurationToken,
			trt__GetMetadataConfigurationOptions->ProfileToken,
			trt__GetMetadataConfigurationOptionsResponse->Options);

	return SOAP_OK;
}


/** Auto-test server operation __trt__GetAudioOutputConfigurationOptions */
int __trt__GetAudioOutputConfigurationOptions(struct soap *soap, struct _trt__GetAudioOutputConfigurationOptions *trt__GetAudioOutputConfigurationOptions, struct _trt__GetAudioOutputConfigurationOptionsResponse *trt__GetAudioOutputConfigurationOptionsResponse)
{	
	/* Return incomplete response with default data values */
	INFO(stderr);

	trt__GetAudioOutputConfigurationOptionsResponse->Options = (struct tt__AudioOutputConfigurationOptions*)soap_malloc(soap, sizeof(struct tt__AudioOutputConfigurationOptions));
	get_aoconfig_options(soap, trt__GetAudioOutputConfigurationOptions->ConfigurationToken,
			trt__GetAudioOutputConfigurationOptions->ProfileToken,
			trt__GetAudioOutputConfigurationOptionsResponse->Options);

	return SOAP_OK;
}


/** Auto-test server operation __trt__GetAudioDecoderConfigurationOptions */
int __trt__GetAudioDecoderConfigurationOptions(struct soap *soap, struct _trt__GetAudioDecoderConfigurationOptions *trt__GetAudioDecoderConfigurationOptions, struct _trt__GetAudioDecoderConfigurationOptionsResponse *trt__GetAudioDecoderConfigurationOptionsResponse)
{	
	/* Return incomplete response with default data values */
	INFO(stderr);

	trt__GetAudioDecoderConfigurationOptionsResponse->Options = (struct tt__AudioDecoderConfigurationOptions *)soap_malloc(soap,sizeof(struct tt__AudioDecoderConfigurationOptions));
	get_adeconfig_options(soap, trt__GetAudioDecoderConfigurationOptions->ConfigurationToken,
			trt__GetAudioDecoderConfigurationOptions->ProfileToken,
			trt__GetAudioDecoderConfigurationOptionsResponse->Options);

	return SOAP_OK;
}


/** Auto-test server operation __trt__GetGuaranteedNumberOfVideoEncoderInstances */
int __trt__GetGuaranteedNumberOfVideoEncoderInstances(struct soap *soap, struct _trt__GetGuaranteedNumberOfVideoEncoderInstances *trt__GetGuaranteedNumberOfVideoEncoderInstances, struct _trt__GetGuaranteedNumberOfVideoEncoderInstancesResponse *trt__GetGuaranteedNumberOfVideoEncoderInstancesResponse)
{	
	/* Return incomplete response with default data values */
	INFO(stderr);

	int size = ve_instances_num;
	int i;
	char *p = trt__GetGuaranteedNumberOfVideoEncoderInstances->ConfigurationToken;
	for(i=0;i<size&&p;i++)
	{
		if(strstr(ve_instances[i][VE_INST_VSCFG],p) != NULL)
		{
			trt__GetGuaranteedNumberOfVideoEncoderInstancesResponse->TotalNumber = atoi(ve_instances[i][VE_INST_TOTNUM]);
			trt__GetGuaranteedNumberOfVideoEncoderInstancesResponse->JPEG = (int *)soap_malloc(soap, sizeof(int));
			trt__GetGuaranteedNumberOfVideoEncoderInstancesResponse->H264 = (int *)soap_malloc(soap, sizeof(int));
			trt__GetGuaranteedNumberOfVideoEncoderInstancesResponse->MPEG4 = (int *)soap_malloc(soap, sizeof(int));

			*trt__GetGuaranteedNumberOfVideoEncoderInstancesResponse->JPEG = atoi(ve_instances[i][VE_INST_JPEG]);
			*trt__GetGuaranteedNumberOfVideoEncoderInstancesResponse->H264 = atoi(ve_instances[i][VE_INST_H264]);
			*trt__GetGuaranteedNumberOfVideoEncoderInstancesResponse->MPEG4 = atoi(ve_instances[i][VE_INST_MPEG4]);

			break;
		}
	}

	return SOAP_OK;
}


/** Auto-test server operation __trt__GetStreamUri */
int __trt__GetStreamUri(struct soap *soap, struct _trt__GetStreamUri *trt__GetStreamUri, struct _trt__GetStreamUriResponse *trt__GetStreamUriResponse)
{	
	/* Return incomplete response with default data values */
	DBG("__trt__GetStreamUri\n");

	/* Response */
	trt__GetStreamUriResponse->MediaUri = (struct tt__MediaUri *)soap_malloc(soap, sizeof(struct tt__MediaUri));
	trt__GetStreamUriResponse->MediaUri->Uri = (char *)soap_malloc(soap, sizeof(char) * XADDR_LEN);
	char *p = get_rtsp_uri(trt__GetStreamUri->ProfileToken,trt__GetStreamUri->StreamSetup);
	if(p == NULL)
	{
		p = rtsp_uri[0];
	}
	strcpy(trt__GetStreamUriResponse->MediaUri->Uri,p);

	trt__GetStreamUriResponse->MediaUri->InvalidAfterConnect = 0;
	trt__GetStreamUriResponse->MediaUri->InvalidAfterReboot = 0;
	trt__GetStreamUriResponse->MediaUri->Timeout = 0;//2000;
	trt__GetStreamUriResponse->MediaUri->__size = 0;
	trt__GetStreamUriResponse->MediaUri->__any = NULL; //must set null or would fail
	trt__GetStreamUriResponse->MediaUri->__anyAttribute = NULL;//must set null or would fail
	return SOAP_OK;
}


/** Auto-test server operation __trt__StartMulticastStreaming */
int __trt__StartMulticastStreaming(struct soap *soap, struct _trt__StartMulticastStreaming *trt__StartMulticastStreaming, struct _trt__StartMulticastStreamingResponse *trt__StartMulticastStreamingResponse)
{	
	return SOAP_OK;
}


/** Auto-test server operation __trt__StopMulticastStreaming */
int __trt__StopMulticastStreaming(struct soap *soap, struct _trt__StopMulticastStreaming *trt__StopMulticastStreaming, struct _trt__StopMulticastStreamingResponse *trt__StopMulticastStreamingResponse)
{	
	return SOAP_OK;
}


/** Auto-test server operation __trt__SetSynchronizationPoint */
int __trt__SetSynchronizationPoint(struct soap *soap, struct _trt__SetSynchronizationPoint *trt__SetSynchronizationPoint, struct _trt__SetSynchronizationPointResponse *trt__SetSynchronizationPointResponse)
{	
	return SOAP_OK;
}


/** Auto-test server operation __trt__GetSnapshotUri */
int __trt__GetSnapshotUri(struct soap *soap, struct _trt__GetSnapshotUri *trt__GetSnapshotUri, struct _trt__GetSnapshotUriResponse *trt__GetSnapshotUriResponse)
{	
	/* Return incomplete response with default data values */
	DBG("__trt__GetSnapshotUri\n");
	trt__GetSnapshotUriResponse->MediaUri = (struct tt__MediaUri *)soap_malloc(soap,sizeof(struct tt__MediaUri));
	trt__GetSnapshotUriResponse->MediaUri->Uri = (char *)soap_malloc(soap,sizeof(char)*XADDR_LEN);
	char * p = get_snapshot_uri(trt__GetSnapshotUri->ProfileToken);
	if(p == NULL) p = snapshot_uri[0];
	strcpy(trt__GetSnapshotUriResponse->MediaUri->Uri,p);
	trt__GetSnapshotUriResponse->MediaUri->InvalidAfterConnect = 0;
	trt__GetSnapshotUriResponse->MediaUri->InvalidAfterReboot = 0;
	trt__GetSnapshotUriResponse->MediaUri->Timeout = 2;	//seconds
	trt__GetSnapshotUriResponse->MediaUri->__size = 0;
	trt__GetSnapshotUriResponse->MediaUri->__any = NULL;
	trt__GetSnapshotUriResponse->MediaUri->__anyAttribute = NULL;
	return SOAP_OK;
}
